用例依賴管理

Oui.發表於2020-11-09

1、場景:用例B的執行依賴用例A,只有當用例A執行成功,用例B才會執行,否則用例B跳過

2、解決方案:pytest-dependency

3、安裝外掛:pip install pytest-dependency

4、使用栗子:

# -*- coding: utf-8 -*-
# @Author : wrx
import pytest


class Test_A:
    @pytest.mark.dependency(name="a", scope="package")
    def test_aa(self):
        print("testA _________________________________")
# -*- coding: utf-8 -*-
# @Author : wrx
import pytest


class Test_B:
    # @pytest.mark.dependency(name="b", depends=["test1/test_a.py/Test_A::test_aa"], scope="package")
    @pytest.mark.dependency(name="b", depends=["a"], scope="package")
    def test_bb(self):
        print("testB _________________________________")

5、關於pytest-dependency:

官方:https://pytest-dependency.readthedocs.io/en/latest/usage.html#basic-usage

dependency的作用範圍:session、package、module、class

相關文章