I’m working on a project with the following directory structure:
workspace/
environment.yml
pyproject.toml
root_project_directory/
__init__.py
main.py
module/
__init__.py
submodule.py
helpermodule.py
tests/
__init__.py
test_submodule.py
I need to set the PYTHONPATH
environment variable to include multiple directories (root_project_directory
and possibly others) so that my Python imports work correctly during development and testing.
Here is my current environment.yml
file:
name: langchain-env
channels:
- conda-forge
- defaults
dependencies:
- python=3.10
- pip
- pip:
- poetry
variables:
PYTHONPATH: "root_project_directory"
Problem
When I activate the Conda environment and run my tests, I encounter ImportError
issues indicating that Python can’t find the modules in the specified directories. For example, in root_project_directory/module/submodule.py
, I have the following import:
from module import helpermodule
In root_project_directory/tests/test_submodule.py
, I attempt to import submodule
:
from module import submodule
def test_example():
assert submodule.some_function() == "expected_value"
When running python -m unittest discover -s root_project_directory/tests
, I get an import error:
ImportError: No module named 'module'
Desired Solution
I would like to set up the PYTHONPATH
correctly in the environment.yml
file for the Conda environment to resolve import errors during testing.