python自动化测试——pytest测试用例setup和teardown

Posted 不放弃自己

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python自动化测试——pytest测试用例setup和teardown相关的知识,希望对你有一定的参考价值。

import pytest

class TestCase():
    def setup_class(self):
        print("setup_class:所有用例执行之前")

    def setup_method(self):
        print("setup_method:  每个用例开始前执行")

    def teardown_method(self):
        print("teardown_method:  每个用例结束后执行")

    def teardown_class(self):
        print("teardown_class:所有用例执行之后")

    def test_A(self):
        print("用例A")
        assert True

    def test_B(self):
        print("用例B")
        assert True

执行命令:pytest -s testOrder.py

执行顺序
setUpClass->setUp->testA->tearDown->setUp->testB>tearDown->tearDownClass


以上是关于python自动化测试——pytest测试用例setup和teardown的主要内容,如果未能解决你的问题,请参考以下文章