Hi there, I can’t seem to figure this out. I am trying to run nosetests on a project. This project imports from another file in the same directory. When I run the file directly, nothing goes wrong. When I run my tests with nosetests, I get an error concerning the import statement (that is in the module, not in the test file). It seems to have something to do with the tests being in another directory than the modules, and nosetests trying to import the file from the tests file path.
My directory structure is:
textgame/ setup.py bin/ bureaucratica/ data/ (a bunch of txt files) __init__.py game.py lexicon.py docs/ tests/ __init__.py bureaucratica_tests.py
In ‘game.py’ I use ‘import lexicon’. This works fine when running game.py.
However, when running nosetests this gives an import error:
File “/home/pi/projects/textgame/bureaucratica/game.py”, line 14, in
ModuleNotFoundError: No module named ‘lexicon’
When I change it to ‘from bureaucratica import lexicon’ nosetests works.
But then, running game.py itself gives an import error.
Is there a way to make both work?