出现问题:

今天在Jenkins中新建一个Job运行自动化测试用例,看见这个报错,在本地的pycharm里面运行对应的脚本,没有任何问题,但是在pycharm的Terminal中使用命令行运行又会报相同的错误

========================================================================================= ERRORS ==========================================================================================
__________________________________________________________ ERROR collecting testcase/loan/loan_case/uitask/test_loan_task_api.py __________________________________________________________
ImportError while importing test module 'D:\seven\testcase\loan\loan_case\uitask\test_loan_task_api.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
testcase\loan\loan_case\uitask\test_loan_task_api.py:5: in <module>
    from base.ssoLogin import Login
E   ModuleNotFoundError: No module named 'base'

解决办法:

在对应的脚本中增加一个conftest.py文件,增加以下代码,再次运行就可以通过了

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


 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐