Skip to content

Instantly share code, notes, and snippets.

@bergantine
Created March 2, 2014 14:39
Show Gist options
  • Save bergantine/9307530 to your computer and use it in GitHub Desktop.
Save bergantine/9307530 to your computer and use it in GitHub Desktop.
__init__.py file for a #Django #tests directory to run any or each #test in that #directory (for Django < 1.6)
import pkgutil
import unittest
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
module = loader.find_module(module_name).load_module(module_name)
for name in dir(module):
obj = getattr(module, name)
if isinstance(obj, type) and issubclass(obj, unittest.case.TestCase):
exec ('%s = obj' % obj.__name__)
@bergantine
Copy link
Author

For Django > 1.6 tests can be in a tests directory with an empty __init__.py file. They just need to be named test_<something>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment