安装虚拟环境
python3 -m venv tutorial-env
启动虚拟环境
source bin/activate
数据驱动
import pytest
import yaml
class TestDemo:
@pytest.mark.parametrize(“env”, yaml.safe_load(open(“env.yml”)))
def test_demo(self,env):
if “test” in env:
print(“test测试环境”)
print(“测试环境ip:”,env[“test”])
elif “env” in env:
print(“env虚拟测试环境”)
class TestData:
# @pytest.mark.parametrize(argnames,argvalues)
# argnames要参数化的变量,string,list,tuple
# argvalues:参数化的值,list,list[tuple]
# 字符串
@pytest.mark.parametrize(“a,b”,[(1,2),(2,2)])
def test_data(self,a,b):
print(a+b)
# 元组
@pytest.mark.parametrize((“c”,“d”),[(1, 2), (2, 2)])
def test_data1(self, c, d):
print(c + d)
# 列表
@pytest.mark.parametrize([“e”,“f”],[(1, 2),(2,2),(4,6)])
def test_data2(self, e, f):
print(e+f)