Tag Archives: E ModuleNotFoundError: No module named ‘common

[Solved] Pytest Error: E ModuleNotFoundError: No module named ‘common

Hint: make sure your test modules/packages have valid Python names. Pytest error
_____________________________________________________________________________________ ERROR collecting test_panda_1.py ______________________________________________________________________________________
ImportError while importing test module

'D:\pythonhome\pandabus_API_test_pytest\case\test_panda_1.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_panda_1.py:7: in <module>
from common.logger import log
E ModuleNotFoundError: No module named 'common

 

Solution:

Method 1: Create a new conftest.py file in the root directory where you want to execute pytest; the contents of the file

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '. ')))

Method 2: pyteset contains __init__.py files in each directory under the test case directory; execute it in the project’s follow directory, which is also possible, as tested