Support for custom test suites
|Reported by:||Owned by:||Adrian Holovaty|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Django uses unittest.defaultTestLoader.loadTestsFromModule for automatically building a test suite from a module. The Python unittest documentation suggests that test modules provide a "suite" functon that returns a pre-built test suite. This is useful if you have test case classes that accept/require additional initialization parameters.
(In my own project, for example, I have some feature tests that need to be run under different user environments, first as an anonymous user, then as a registered user. Instead of writing the same test twice or building a loop around it, I just create two test case instances which different "user" parameters.)
The attached patch for django/test/simple.py checks if the "tests" module of an app has a "suite" attribute. If this is the case, we assume it is a function that returns a complete suite for this module, otherwise we build the test suite ourselves using loadTestsFromModule.