# 下载插件 pip install pytest-dependency |
import pytest def test_01(): print("用户注册") assert 1 == 0 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
import pytest @pytest.mark.dependency() # 被依赖的用例同样需要装饰 def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test_01"]) # depends 列表中接收需要依赖的用例名称,如果依赖多个,则直接将用例名称写入到列表即可 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =================== |
import pytest @pytest.mark.dependency(name='test') # name 设置别名 def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test"]) # depends 填写依赖的别名 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =============================== |
test_demo.py::test_01 FAILED [ 50%] # 加粗部分就是pytest对用例的完全限定名 test_demo.py::test_02 SKIPPED (test_02 depends on test) [100%] |
import pytest def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test_demo.py::test_01"]) def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =============================== |
# 下载插件 pip install pytest-dependency |
import pytest def test_01(): print("用户注册") assert 1 == 0 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
import pytest @pytest.mark.dependency() # 被依赖的用例同样需要装饰 def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test_01"]) # depends 列表中接收需要依赖的用例名称,如果依赖多个,则直接将用例名称写入到列表即可 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =================== |
import pytest @pytest.mark.dependency(name='test') # name 设置别名 def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test"]) # depends 填写依赖的别名 def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =============================== |
test_demo.py::test_01 FAILED [ 50%] # 加粗部分就是pytest对用例的完全限定名 test_demo.py::test_02 SKIPPED (test_02 depends on test) [100%] |
import pytest def test_01(): print("用户注册") assert 1 == 0 @pytest.mark.dependency(depends=["test_demo.py::test_01"]) def test_02(): print("用户登录") if __name__ == '__main__': pytest.main(["test_demo.py"]) |
=========================== short test summary info =========================== FAILED test_demo.py::test_01 - assert 1 == 0 ================== 1 failed, 1 skipped in 0.23s =============================== |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |