I have my tests for a Django application in a tests directory:
my_project/apps/my_app/
├── __init__.py
├── tests
│ ├── __init__.py
│ ├── field_tests.py
│ └
If you use django-nose you can use a simple selector:
from nose.selector import Selector
from nose.plugins import Plugin
import os
import django.test
class 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 parts
class 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']