如何在多个自定义环境中并行运行我的pytest?我也有发热症。不确定这个插件是否有帮助
test_test.py
@pytest.mark.env("env1", "env2", "env3")
def test_check(env):
print("Chosen {} for test_check function".format(env))
@pytest.mark.env("env1", "env2")
def test_check2(env):
print("Chosen {} for test_check2 function".format(env))
@pytest.mark.env("env1")
def test_check3(env):
print("Chosen {} for test_check3 function".format(env))当我运行命令时:
pytest -v -s test_test.py --env env1这是我的输出..。
collected 3 items
conftest.py::test_check Chosen env1 for test_check function
PASSED
conftest.py::test_check2 Chosen env1 for test_check function
PASSED
conftest.py::test_check3 Chosen env1 for test_check function
PASSED
============================================================= 3 passed in 0.02 seconds ==============================================================类似地,当我运行命令时:
pytest -v -s test_test.py --env env2这是我的输出..。
collected 2 items
conftest.py::test_check Chosen env2 for test_check function
PASSED
conftest.py::test_check2 Chosen env2 for test_check function
PASSED
============================================================= 2 passed in 0.02 seconds ==============================================================我这里有两个条件,
所以我选择了xdist插件,但是我不确定我是否能用我的例子运行。对于我的示例,可以使用xdist运行吗?
我需要这样的东西..。
pytest -v -s -d --tx test_test.py --env env1 --env env2要同时运行两个env1,env2
发布于 2022-05-12 09:59:50
检查一下这个:
-dist加载组:测试按xdist_group标记分组。组被作为一个整体分配给可用的工人。这可以保证所有具有相同xdist_group名称的测试都在同一个工作人员中运行。
@pytest.mark.xdist_group(name="group1")
def test1():
pass
class TestA:
@pytest.mark.xdist_group("group1")
def test2():
pass这将确保test1和TestA::test2在同一个工作器中运行。没有xdist_group标记的测试通常分布在--dist=load模式中。
https://pypi.org/project/pytest-xdist/#:~:text=--dist%20loadgroup%3A%20Tests,dist%3Dload%20mode。
https://stackoverflow.com/questions/56596696
复制相似问题