Tag Archives: pytest cmd error

Execute an error under pytest cmd make sure your test modules/packages have valid Python names.

Problem Description:

Use pytest.main([‘TestcasePairValue.py’]) to execute OK in the case code, but use pytest TestcasePairValue.py under cmd to execute the error as follows

Importing the while Test Module1 ImportError ‘D: \ code \ APITEST \ TestCase \ TestcasePairValue.py’.
Hint: the make your Test modules Sure / Packages have have Valid

I checked the online information and said that there was a circular reference, but I checked the two files and did not see where there is mutual reference. Finally, I found a solution to the big problem. Record it:

Create a new conftest.py file in the executed case file directory, and write the content:

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

Get it done! It can be executed on the console normally!