How do I tell django-nose where my tests are?
If you use django-nose you can use a simple selector:
from nose.selector import Selectorfrom nose.plugins import Pluginimport osimport django.testclass TestDiscoverySelector(Selector): def wantDirectory(self, dirname): parts = dirname.split(os.path.sep) return 'my_app' in parts def wantClass(self, cls): return issubclass(cls, django.test.TestCase) def wantFile(self, filename): parts = filename.split(os.path.sep) return 'test' in parts and filename.endswith('.py') def wantModule(self, module): parts = module.__name__.split('.') return 'test' in partsclass TestDiscoveryPlugin(Plugin): enabled = True def configure(self, options, conf): pass def prepareTestLoader(self, loader): loader.selector = TestDiscoverySelector(loader.config)
This is just an example implementation and you can make it more configurable or adjust it to your needs. To use it in your Django project just provide the following option in settigs.py
NOSE_PLUGINS = ['lorepo.utility.noseplugins.TestDiscoveryPlugin']
Wrong:
python manage.py test my_app.tests.storage_tests:TestCase.test_name
is in fact with slashes until the class name and with the extension of the file
Right:
python manage.py test my_app/tests/storage_tests.py:TestCase.test_name
nose will pick automatically, if you add test = True in the beginning of module and if your methods starts with test_
see how nose detects tests http://nose.readthedocs.io/en/latest/finding_tests.html