Home > Net >  pytest no module named common
pytest no module named common

Time:12-23

I'm trying to get started with python and pytest, I have the following project structure :

.
├── my_module
│   ├── __init__.py
│   ├── common
│   │   ├── __init__.py
│   │   └── utils.py
│   └── my_script.py
└── test
    ├── __init__.py
    └── test_my_script.py

When I run tests (using pytest), I get an error:

no module named 'common'.

I have also the following all configs files:

  • tox.ini
  • setup.py
  • setup.cfg
  • pyproject.toml


someone know what I missed?
EDIT here is how I import utils from test_my_script.py :

from common.util import func1,func2

CodePudding user response:

common.util module is not accessible from your test execution because it is located in my_module package. You should use import starting from working directory which is your project root.

Consider using following import instead:

from my_module.common.util import func1, func2
  • Related