Search code examples
pythonunit-testingpython-nose

How to organize python test in a way that I can run all tests in a single command?


Currently my code is organized in the following tree structure:

src/
    module1.py
    module2.py
    test_module1.py
    test_module2.py
    subpackage1/
        __init__.py
        moduleA.py
        moduleB.py
        test_moduleA.py
        test_moduleB.py

Where the module*.py files contains the source code and the test_module*.py contains the TestCases for the relevant module.

With the following comands I can run the tests contained in a single file, for example:

$ cd src
$ nosetests test_filesystem.py
..................
----------------------------------------------------------------------
Ran 18 tests in 0.390s

OK

How can I run all tests? I tried with nosetests -m 'test_.*' but it doesn't work.

$cd src
$ nosetests -m 'test_.*'

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Thanks


Solution

  • If they all begin with test then just nosetest should work. Nose automatically searches for any files beginning with 'test'.