1、pytest.mark.parametrize装饰器可以实现测试用例参数化。
2、实例:
import pytest @pytest.mark.parametrize("req,expect", [("3+5",8), ("1+1",2), ("8-1",7) ]) def test11(req,expect): assert eval(req)==expect if __name__ == '__main__': pytest.main(["-s","text_01.py"])
运行结果:
3、有时候功能变动,用例就会失败,这种预料之类会失败的用例可以标记为忽视,暂不运行。使用内置的mark.xfai
import pytest @pytest.mark.parametrize("req,expect", [("3+5",8), ("1+1",2), pytest.param("6 * 9", 42, marks=pytest.mark.xfail)#用例失败,标记忽视 ]) def test11(req,expect): assert eval(req)==expect if __name__ == '__main__': pytest.main(["-s","text_01.py"])
运行结果:
原文地址:https://www.cnblogs.com/guo2733/p/10530578.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。