file accessibility across directories?
James Hartley <[email protected]> Wed, 28 Feb 2024 12:02:50 -0600
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <CAKeNXXv+FLC=-eG3whzOTV-JpT=2kYChxV8jfG0pxt8joFRxCw@mail.gmail.com> |
I am having issues with accessing files across different directories. The
file structure I am using is simple:
+-project
|
+- .git
+-src
| |
| +- foo.py
| +- bar.py
|
+- tests
| |
| +- test_foo.py
|
+- utils
|
+- baz.py
Test files within project/tests reference classes successfully in foo.py
through Pytest as:
from src.foo import Foo
Pytest is actually executed from the ./project directory successfully as:
python -m pytest -v tests/test_foo.py
baz.py had been in the src directory, where it successfully referenced
class Foo as:
from foo import Foo
Now baz.py has been moved to utils/baz.py. I would think that this would
require the import statement to changed to:
from src.foo import Foo
...but I receive a "ModuleNotFoundError: No module named 'src'" error.
I have tried adding an empty src/__init__.py file which doesn't change the
error received. I always invoke the Python interpreter from the project
directory. Always.
The ./project/tests directory does not have a __init__.py file present. To
date, I have not required this file anywhere, so I have not created it.
Any insights shared which can help me resolve this simple issue would be
appreciated.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor