0

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
2
  • 3
    Could you please share code of test_my_script.py module. I suggest that you have something like from common import .... In this case you should try to change it to from my_module.common import ... Commented Dec 22, 2022 at 9:04
  • Please review @pL3b 's comment, looks like it might be helpful considering the updates from your recent edit. Commented Dec 22, 2022 at 9:31

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.