首页 > 其他 > 详细

pytest 框架 学习总结

时间:2019-12-10 16:33:57      阅读:83      评论:0      收藏:0      [点我收藏+]

 

  • 1.用例顺序
    
    setup_module
    setup_class
    setup_method
    teardown_method
    teardown_class
    teardown_module
    
    2. 使用pytest-order控制用例之间的顺序控制,直接引用官方例子:
    第一种方法:
    import pytest
    
    @pytest.mark.order2
    def test_foo():
        assert True
    
    @pytest.mark.order1
    def test_bar():
        assert True
    
    第二种方法:
    
    import pytest
    
    @pytest.mark.second_to_last
    def test_three():
        assert True
    
    @pytest.mark.last
    def test_four():
        assert True
    
    @pytest.mark.second
    def test_two():
        assert True
    
    @pytest.mark.first
    def test_one():
        assert True
    
    第三种方法:
    import pytest
    
    @pytest.mark.run(order=-2)
    def test_three():
        assert True
    
    @pytest.mark.run(order=-1)
    def test_four():
        assert True
    
    @pytest.mark.run(order=2)
    def test_two():
        assert True
    
    @pytest.mark.run(order=1)
    def test_one():
        assert True
    
    更多用法,请查看官方文档:
    https://pytest-ordering.readthedocs.io/en/develop/
    
    3. 参数化以及 打印日志
    
    import pytest
    import logging
    logging.basicConfig(level=logging.DEBUG)
    class TestA:
        def setup(self):
            logging.info("setup开始执行")
    
        def teardown(self):
            logging.info("teardown 完成")
    
        def add(self, a, b):
            return (a + b)
    
        @pytest.mark.parametrize("a, b, c", [
        (1, 1, 2),
        (1, 0, 1),
        (1, -1, 2),
        (1, 1000000, 1000001)
        ])
        def test_add(self, a, b , c):
            print(a,b,c)
            assert self.add(a, b)==c
    

      

pytest 框架 学习总结

原文:https://www.cnblogs.com/tQlve/p/12016961.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!