Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 01:00 AM
Hello
Import errors happen often with Pytest. To Debug this error you can add this in your "test_myfunction_test.py":
import sys
# printing all directories for
# interpreter to search
sys.pathsys.path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module
In order to do from src.myfunctionfile, your project directory needs to be in the list of "sys.path" paths
A quick fix would be to use
sys.path.append("/you/project/directory") Otherwise you should check how your PYTHONPATH variable is set or your pytest.ini file
Hope this helps 🙂