Thrown pytest execution cases from conftest.py ModuleNotFoundError: No module named 'XXX' abnormal solutions

I. Description of the problem

  The implementation of the project root directory of the entire test case, threw out ModuleNotFoundError directly from conftest.py module: No module named 'TestDatas' exception:

  

Second, the solution

  By the way the investigation confirmed that the imported module is correct, conftest.py has not succeeded in introducing this module, where the relationship comes to execution path, TestDatas directory in the root directory of the project, is the coverage pytest, we only need to change conftest .py execution path on it, add the following code in the module conftest.py

import sys, os

sys.path.append((os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))))

Guess you like

Origin www.cnblogs.com/xiaogongjin/p/11708316.html