Draymonders / Code-Life

The marathon continues though.
27 stars 3 forks source link

Pytest #108

Open Draymonders opened 3 years ago

Draymonders commented 3 years ago

reference

pytest用例规则

-s参数是为了显示用例的打印信息, -q参数只显示结果,不显示过程。

setup / teardown

fixture scope

fixture实现setup/teardown

class Test_fixture:

    @pytest.fixture(scope="function", name="begin")
    def test_begin(self):
        print("begin")
        a = 1
        yield 1
        print("end")

    @pytest.fixture(scope="class", name="begin2")
    def test_begin2(self):
        print("begin2")
        yield
        print("end2")

    @pytest.mark.usefixtures("begin", "begin2")
    def test_process(self, begin):
        print("process")
        print("begin return: {}".format(begin))

    @pytest.mark.usefixtures("begin2")
    def test_process2(self, begin2):
        print("process2")
        assert 1 == 2

"""
begin2
begin
process
begin return: 1
end

process2
end2
"""