作者Talent14 (Talent)
看板Python
标题[问题] Pytest问题
时间Sat Feb 20 18:05:21 2021
请问使用python的pytest测试框架, 如何将自订的pytest指令参数值传到每个test case档案中pytest.mark.skipif的条件判断使用?
EX: pytest --par=1, par的值用来判断所有Test Case是否要Skip的依据
@pytest.mark.skipif(par > '1', reason='pass test1') --> 若par值大於 1 才skip测试案例
PS: 查了一些资料,看到用pytest.config方式取得值,但pytest版本目前使用6.X,pytest没有config这个attribute
(ERROR MSG: AttributeError: module 'pytest' has no attribute 'config')
附上测试程式码图片
https://i.imgur.com/kqZmsc2.jpg
https://i.imgur.com/YWcClDR.jpg
先感谢各位大大!
-----
Sent from JPTT on my iPhone
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.38.29.74 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1613815523.A.6E2.html
1F:→ djshen: def pytest_markeval_namespace(config): 02/20 21:15
2F:→ djshen: return {'par': config.getoption('par')} 02/20 21:15
3F:→ djshen: @pytest.mark.skipif('par == 1') 02/20 21:15
4F:→ Talent14: 谢谢d大,我会再研究试试看! 02/20 23:36
5F:→ Talent14: 使用pytest_markeval_namespace已成功,也在pytest6.2.0 02/20 23:48
6F:→ Talent14: 官方文件中查到相关使用方式与说明!非常感谢大大! 02/20 23:48
7F:→ djshen: 也可以参考_pytest.skipping.evaluate_condition 02/21 00:31
8F:→ djshen: 可以看到他eval str的时候用了哪些global variable 02/21 00:32
9F:→ Talent14: 好的,我会再研究研究,谢谢提供建议与资讯! 02/21 08:56