pytest框架学习2——依赖

使用pytest构建项目时:

  1. 继承关系改为继承object
  2. setup方法改为pytest的setup方法
  3. 断言使用assert
  4. 使用pytest依赖插件:pip install pytest-dependency

实例1:

import pytest

@pytest.mark.dependency(name="t1")
def test11():
    return 1
    print("test11")

# @pytest.mark.dependency(depends=["t1"],scope="module")
@pytest.mark.dependency(depends=["t1"])
def test12():
    print("test12")


if __name__ == '__main__':
    pytest.main(['-sv','test1.py'])

实例2:

import pytest

@pytest.mark.dependency()
def test13():
    return 1
    print("test11")

@pytest.mark.dependency(depends=["test13"])
def test14():
    print("test12")

结果:

pytest框架学习2——依赖

 

被依赖的的用例需要标记:

  @pytest.mark.dependency(name="t1")

使用依赖的用例需要引用依赖:

  @pytest.mark.dependency(depends=["t1"],scope="module")

    depends=["t1"]:依赖名为"t1"的用例

    scope="module"表示模块之间的依赖关系 

  @pytest.mark.dependency(depends=["t1"])

 

上一篇:异常org.springframework.beans.factory.NoSuchBeanDefinitionException


下一篇:SpringIOC