Following this file structure, my project looks as follows (simplified):
Project/
|-- project/
|-- test/
|-- test_foo.py
|-- foo.py
Using best practices, how should I import foo from within test_foo.py? I’m aware of relative imports, but PEP 8 discourages them.
In unit tests, at least those for external interfaces, prefer absolute imports. Tests should look as much like client code as possible, and they should break when things get moved around, when an
__init__.pydoesn’t properly re-export from modules, etc.