FabrizioM's answer should make it work. Here is a little explanation.
When Python downloads a file, it searches the file system. So we have an import statement:
from ex47.game import Room
It searches for the ex47.py file in the module search path (accessible as sys.path in Python code). The module search path contains some directories based on the Python installation details, directories listed in the PYTHONPATH environment variable, and contains the parent directory of the script you are running. He does not find ex47.py in the path, but he sees that inside it there is a directory named ex47 with __init__.py . He then finds game.py in this folder.
The problem is that your current folder is not in the module search path. Since ex47_tests.py has been started, it has $ cwd / tests on the way. You need $ cwd on the way.
PYTHONPATH=. python tests/ex47_tests.py
does just that. It puts $ cwd in the module search path, so Python can find the source files.
You can also do:
python -m tests.ex47_tests
This will work as a module, not a file, while it will use the current directory as the path that it automatically adds to the module search path, and not the directory in which the file is located.
source share