pytest-命令行传入自定义的参数到测试文件中

pytest-命令行传入自定义的参数到测试文件中

conftest.py

import pytest
def pytest_addoption(parser):
parser.addoption("--aa", action="store", default='', help="the input params")
# parser.addoption("--outdir", action="store", default="~/benchmark/model/", type=str,
# help="the outdir of obj")
@pytest.fixture
def aa(request):
return request.config.getoption("--aa")

test.py

import pytest
def test_answer(aa):
# if a == "type1": #获取命令行传参的值后进行判断
# print("first")
# elif a == "type2":
# print("second")
# assert 0 # to see what was printed
if aa == " " or aa == "":
exit -1
else:
print('\n')
print(12312412412)
print(aa)
print(type(aa))
# if __name__ == "__main__":
# pytest.main(["-s", "test.py"])

https://www.it-swarm.cn/zh/python/如何通过命令行在pytest中传递参数/829127083/

posted @   michaelchengjl  阅读(466)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示