First, you need to make sure tests
is not just a directory, but a Python package by creating an __init__.py
in it.
You also need to make sure you name the modules in your tests
package test_something.py
.
Most test runners, as part of their test discovery, look for a module or package named tests
, modules in that package starting with test_
and expect method names for test methods (on TestCase
subclasses) to start with test_
.
The unittest module describes test runners as:
A test runner is a component which orchestrates the execution of tests
and provides the outcome to the user. The runner may use a graphical
interface, a textual interface, or return a special value to indicate
the results of executing the tests.
There are plenty of different testing frameworks and hence test runners out there, most extending unittest
in some way and looking for unittest.TestCase
subclasses. They may do different types of test discovery, present the results in a different way or gather code coverage while the tests are being run.
As for relative imports: You should really try to avoid these. They make it harder to move code around (as you just noticed) and decrease the readability of the imports (where does what code get imported from?). Just use from myproject.views import my_view
- it's a lot clearer where things live