【发布时间】:2020-06-14 16:17:23
【问题描述】:
我对以下代码有问题——最终结果与预期不符:
env.yaml
config:
requestenv: [test, uat]
envinfo:
test: [{imp: 111, clk: 111, "act": 111}, {imp: 222, clk: 222, act: 222}]
uat: [{ imp: 333, clk: 333, act: 333 }, { imp: 444, clk: 444, act: 444 }]
test_env.py
import pytest
from utils import configutil
configpath = r".\monitor.request.config.yaml"
config = configutil.readyamlconfig(configpath)
requestenv = config["config"]["requestenv"]
@pytest.fixture(scope="function", params=requestenv)
def one(request):
env = request.param
return config["config"]["envinfo"][request.param]
@pytest.mark.parametrize("testdata", [pytest.lazy_fixture("one")])
def test_func01(testdata):
print()
print("*" * 10)
print(testdata)
测试数据总是带有env.yaml 配置文件,并且取决于测试环境(在我的例子中是test 和uat)。我想遍历每个环境和该环境中的每个项目,如下所示运行pytest -s .\test_env.py:
[预期]
test_env.py::test_func01[test-{ imp: 111, clk: 111, act: 111 }]
test_env.py::test_func01[test-{ imp: 222, clk: 222, act: 222 }]
test_env.py::test_func01[saas-{ imp: 333, clk: 333, act: 333 }]
test_env.py::test_func01[saas-{ imp: 444, clk: 444, act: 444 }]
[实际]
test_env.py::test_func01[test-[[{imp: 111, clk: 111, "act": 111}, {imp: 222, clk: 222, act: 222}]]]
test_env.py::test_func01[test-[{ imp: 333, clk: 333, act: 333 }, { imp: 444, clk: 444, act: 444 }]]
【问题讨论】: