Hi Shai, The discover runner does discovery based on pattern.
So, if your tests are named, test_*.py, they would by be discovered by default. Test discovery is recursive, under the root, so it doesn't matter if you have tests in a tests directory. The __init__.py imports would be redundant, and actually ignored by the discover process. If your test files don't match the default pattern of "test*.py", then you have three options: 1) Rename the test files 2) Invoke the test command with a custom pattern 3) Specify a custom load_tests in the __init__.py file that tells discovery what to do. Preston On Apr 1, 2:28 pm, Shai Berger <[email protected]> wrote: > Hi, > > +1 in general. One concern, and one idea: > > > -- Backwards-incompatible changes -- > > > * Some valid test structures in Django don't work with unittest2. For > > instance, tests in `tests/__init__.py` don't match a patter than > > unittest would recognize if running discovery on a module. > > I have a complex app with many tests; so many, that we felt the need to break > the tests module into modules in a package. So we have > tests/test_frobnication.py > tests/test_grobulation.py > etc., and > tests/__init__.py > which imports them all. > > It isn't quite clear to me how this applies to such a structure; it seems like > I would need a special pattern, "tests.test_*.py" or some such. This, in turn, > raises an idea: an app should be able to specify the discovery parameters for > its own tests in the source, not just on the command line. > > Just to be clear: In view of backwards-compatibility concerns, I don't think > the load_tests protocol supported by unittest2 is enough for this. It should > be much simpler, IMO; something like (pseudo code): > > try: > from app import tests > if hasattr(tests, 'root'): > set_discovery_root(tests.root) > if hasattr(tests, 'pattern'): > set_discovery_pattern(tests.pattern) > except ImportError: > pass > > This way, my case is handled simply by adding these lines into > tests/__init__.py: > > root=app.tests > > Thanks, > Shai. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
