3

I have the following directory structure

package
    __init__.py
    module1
        model1.py
    tests
        __init__.py
        common.py
        test_module1
            test_model1.py

I need to:

  1. Have a place to put common 'helpers' for tests, such as shared data. I'm currently using common.py. I think this necessitates having an __init__ in the tests path, so test files can import common.
  2. Not import package before running tests, because I need to test that the configs load correctly (and so need to make changes to environment variables before importing package and test that flows through to its configs). Nosetests seems to insist on importing package if tests is a package (i.e. if there's an __init__ in tests).

Is there a way of doing this? Or should I be changing my setup? I could have common in package directly, although that seems awkward.

A question that touches on this issue: Python imports for tests using nose - what is best practice for imports of modules above current package

Community
  • 1
  • 1
Maximilian
  • 7,512
  • 3
  • 50
  • 63
  • What's wrong with putting the `__init__.py`, Regardless of where you put your `common.py` your tests directory needs to have `__init__.py` otherwise nose will not be able to discover tests from `tests` directory – Kashif Siddiqui Mar 14 '17 at 07:21

0 Answers0