How to organize python test in a way that I can run all tests in a single command?
Question: 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 `TestCase`s 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


Answer: Whether you seperate or mix tests and modules is probably a matter of taste,
although I would strongly advocate for keeping them apart (setup reasons, code
stats etc).

When you're using nosetests, make sure that all directories with tests are
real packages:

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

This way, you can just run `nosetests` in the toplevel directory and all tests
will be found. You need to make sure that `src/` is on the `PYTHONPATH`,
however, otherwise all the tests will fail due to missing imports.

