You should be able to import files into your __init__.py and pick them up. I had this setting:
- app: - __init__.py - models.py - views.py - tests: - __init__.py - models.py # contain tests - views.py # contain tests
In the tests/__init__.py , I had the following:
from app.tests.models import * from app.tests.views import *
Which strikes one of the benefits of using regex to search for tests (nose target), but it worked.
You can also use the @istest decorator to add a separate def as a test if you want to avoid assigning methods to the regular expression. I did not try to do this for modules (py files) that also do not match the regular expression, but I doubt that it will work without the specified import.
Note. I moved away from importing into __init__.py and just prefixed my testing methods and file names with test_ and postfix of my classes with Test. I believe that this makes the code more self-describing, since even in the Test class there can be installation methods and auxiliary methods (for example, generators).
source share