首页 新闻 会员 周边

pytest xdist 执行过滤了main方法传入的addopt的自定义参数

0
[待解决问题]

main_run.py

pytest.main(['-s', '-v','--browser=chrome-headless', 'test_case'])

conftest.py

def pytest_addoption(parser):
parser.addoption("--browser",
action="store",
dest="browser",
default='chrome',
choices=['chrome', 'firefox', 'ie'],
help="定义运行的浏览器,包括chrome、firefox和ie")

@pytest.fixture(scope='session', autouse=True)
def browser(request):
browser_type = request.config.getoption("browser")
global driver
'''定义全局driver参数'''
if driver is None:
with allure.step("打开浏览器"):
driver = BaseDriver(browser_type).driver
yield driver
with allure.step("关闭浏览器"):
driver.close()
报错信息:
error: unrecognized arguments: --browser

martinsun的主页 martinsun | 菜鸟二级 | 园豆:206
提问于:2021-09-06 09:33
< >
分享
所有回答(1)
0

xdist中,如果需要匹配部分用例,需要使用 pytest的 file_or_dir 命令和 -k 命令结合使用,例如
1、模糊匹配某个包下的测试用例,file_or_dir 命令输入包名
pytest.main(['-s', '-v','test_case', '-k test_1case','--browser','chrome'])
2、模糊匹配某个模块下的测试用例,file_or_dir 命令输入完整路径的文件名 项目路径/包名/模块名.py
pytest.main(['-s', '-v','PyTestDemo/test_case/test_1case.py', '-k test_1case','--browser','chrome'])

xdist 中单独使用 -k,如果带了自定义的addopt,会导致命令找不到

martinsun | 园豆:206 (菜鸟二级) | 2021-09-07 15:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册