.
├── mymodule
│   ├── __init__.py
│   └── foo.py
├── tests
    ├── __init__.py
    ├── utils.py
    └── test_module.py
I have the above directory structure for my Python package.
Within the test_module.py file, I need to import tests/utils.py. How should I import it so that I can run the test by using both
- python tests/test_module.py
- pytestfrom the root directory?
Currently, I imported tests/utils.py as follows in the test_module.py file:
from utils import myfunction
Then, pytest will generate the following error:
E   ModuleNotFoundError: No module named 'utils'
If I change to:
from .utils import myfunction
Then, pytest works fine, but python tests/test_module.py generates the following error:
ImportError: attempted relative import with no known parent package
How can I properly import utils.py so that I can use in both ways?
 
    