0
votes

This is a broad question because no one seems to have found a solution to it as yet so I think asking to see a working example might prove more useful. So here goes:

Has anyone run a nosetests on a python project using imports of multiple files/packages?

What I mean is, do you have a directory listing such as:

project/
    |
    |____app/
          |___main.py
          |___2ndFile.py
          |___3rdFile.py
     |____tests/
          |____main_tests.py

Where your main.py imports multiple files and you perform a nosetests from the project file of utilizing a test script in the main_tests.py file? If so please can you screen shot your import section both of all your main files and your main_tests.py file?

This seems to be a major issue in nosetests, with no apparent solution:

1
This is your second question about the same topic. I had asked you two questions you did not address the one that might most likely be the reason for the failure. Refer back to your question and look at the comments again. You shouldn't post the same question twice. But, this is a very common thing that does work. - idjaw
True same topic, different approach. - Jeeves

1 Answers

2
votes
  1. You can't have python modules starting with a digit, so 2ndFile.py, 3rdFile.py won't actually work (rename them).
  2. You'll need an __init__.py inside the app directory, for it to be considered a package, so add that (it can be empty file).
  3. You don't need an __init__.py in the tests directory!
  4. The import statements in main_tests.py should look like from app.main import blah
  5. The absolute path of the project directory needs to be in your sys.path. To achieve this, set an environment variable: export PYTHONPATH=/path/to/project

Now running nosetests should work.