Parallely running parameterized tests in pytest

自作多情 提交于 2020-01-22 20:01:07

问题


I wanted to run parameterized test functions in parallel. This is for a concurrency testing scenario. Same testcase runs in parallel with different parameters in a device. After completing all the parameterized variant of one test function, I want to proceed with the next one.

If we take this simple example, I want to run all 4 instances of test_even parallely and then move to test_odd.

@pytest.mark.parametrize("x", range(4))
def test_even(x):
    assert x % 2 == 0        
@pytest.mark.parametrize("x", range(4))
def test_odd(x):
    assert x % 2 != 0

Is it possible to do in pytest? I checked xdist, but could not find this type of support. Could anybody please give some pointers on how to implement this in pytest?


回答1:


Have a look at pytest-xdist it does a bunch of cool things, including allowing you to run your tests in parallel.

$ pip install pytest-xdist
$ pytest -n <num cpus>


来源:https://stackoverflow.com/questions/29560212/parallely-running-parameterized-tests-in-pytest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!