Search code examples
pythondjangounit-testingpycharmnose

Unable to run Nosetests on classes or functions


I am using pycharm and are trying to run individual tests. My "run all tests works (used py.test), but I want to run specific tests. When I try to run the Nosetest i get this error:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

My wsgi.py looks like this:

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "v3.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()


Solution

  • Have you tried running specific tests using py.test? e.g. on the command line:

    py.test [module_filepath]::[name_of_test]

    In your case, it looks like you might be trying to run a function inside a class, which would look like: py.test test_mod.py::TestClass::test_method

    (Source: http://doc.pytest.org/en/latest/usage.html )

    (reformatted from comments so answer can be accepted)