使用pytest执行测试用例

使用pytest执行测试用例

创建待测用例

import pytest
def test_01():
    print("test 1")
    assert 1==1

def test_02():
    print("test 2")
    assert 0==1
     

调用pytest执行用例

if __name__=="__main__":
    pytest.main(['test_pytest.py'])

执行结果

============================= test session starts =============================
platform win32 -- Python 3.6.7, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: E:\PycharmProjects\untitled1\AutoTest\test
plugins: forked-1.3.0, html-2.1.1, metadata-1.10.0, xdist-2.1.0
collected 2 items

test_pytest.py .F                                                        [100%]

================================== FAILURES ===================================
___________________________________ test_02 ___________________________________

    def test_02():
        print("test 2")
>       assert 0==1
E       assert 0 == 1

test_pytest.py:8: AssertionError
---------------------------- Captured stdout call -----------------------------
test 2
=========================== short test summary info ===========================
FAILED test_pytest.py::test_02 - assert 0 == 1
========================= 1 failed, 1 passed in 0.08s =========================

Process finished with exit code 0

你可能感兴趣的:(pytest,python)