pytest local modules 1

pytest local modules

import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../')

# from https://stackoverflow.com/questions/10253826/path-issue-with-pytest-importerror-no-module-named-yadayadayada

Here is what the above code is Doing:
1. Get the directory of the current file.
2. Add the parent directory to the path.
3. Import the module.

This is a common pattern in Python.

Similar Posts