po模式中采用pytest批量运行用例找不到模块ModuleNotFoundError: No module named 'base'

问题

在对一个软件进行自动化测试时,采用po模式进行设计,在项目根目录创建配置文件pytest.ini来批量运行测试用例。

pytest.ini的内容如下:

[pytest]
# 选项
addopts = -s
# 文件所在目录
testpaths = script/
# 文件名
python_files = test*.py
# 测试类名
python_classes = Test*
# 测试方法名
python_functions = test*

终端运行pytest后出现了如下报错:

image-20260130141445797

解决

在pytest.ini中添加如下配置即可解决:

# 添加项目根目录到Python路径(关键配置)
pythonpath = .

再次运行,问题解决。

posted @ 2026-01-30 14:16  蜀道,难  阅读(0)  评论(0)    收藏  举报