pytest之命令行参数之--setup-show查看fixture的执行过程 || --fixtures获取测试用例执行前可用的fixture || --markers获取测试用例中可用的标记(过滤出某些测试用例执行)
--setup-show查看fixture的执行过程
前言
使用命令行运行 pytest 用例的时候,看不到 fixture 的执行过程。
如果我们想知道fixture的执行过程和先后顺序,可以加上 --setup-show 命令行参数,帮助查看 fixture 的执行过程。
--setup-show
案例参考test_s.py
# test_s.py import pytest @pytest.fixture() def login(): print("前置操作:准备数据") yield print("后置操作:清理数据") def test_01(login): a = "hello" b = "hello" assert a == b def test_02(login): a = "hello" b = "hello world" assert a in b
①命令行执行 pytest test_s.py
>pytest test_s.py ============================= test session starts ============================= collected 2 items test_s.py .. [100%] ========================== 2 passed in 0.10 seconds ===========================
②命令行执行 pytest --setup-show test_s.py
>pytest test_s.py --setup-show ============================= test session starts ============================= collected 2 items test_s.py SETUP S base_url SETUP S _verify_url (fixtures used: base_url) SETUP F __pytest_repeat_step_number SETUP F login test_s.py::test_01 (fixtures used: __pytest_repeat_step_number, _verify_url, base_url, login). TEARDOWN F login TEARDOWN F __pytest_repeat_step_number SETUP F __pytest_repeat_step_number SETUP F login test_s.py::test_02 (fixtures used: __pytest_repeat_step_number, _verify_url, base_url, login). TEARDOWN F login TEARDOWN F __pytest_repeat_step_number TEARDOWN S _verify_url TEARDOWN S base_url ========================== 2 passed in 0.04 seconds ===========================
这样就可以方便查看用例调用了哪些fixture,上面用例里面只写了一个 login fixture函数。
但是从回溯信息上看到还有几个是内置的fixture会自动调用: __pytest_repeat_step_number , _verify_url, base_url 。
--fixtures获取测试用例执行前可用的fixture
--markers获取测试用例中可用的标记(过滤出某些测试用例执行)
去期待陌生,去拥抱惊喜。
分类:
pytest测试框架
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!