如何通过xdist插件并行执行pytest?

时间:2019-06-14 10:51:39

标签: python parallel-processing pytest xdist

如何在多个自定义环境中并行运行pytests?我也有pytest-xdist。不确定此插件是否有帮助

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 ==============================================================

Similary,当我运行命令时:

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 ==============================================================

我在这里有2个要求,

  1. 我想同时运行多个环境
  2. 它需要并行运行

所以我选择了xdist插件;但是我不确定是否可以使用我的示例。对于我的示例,可以使用xdist运行吗?

我需要这样的东西...

pytest -v -s -d --tx test_test.py --env env1 --env env2

同时运行env1,env2

0 个答案:

没有答案