简体   繁体   English

在pytest中并行运行参数化测试

[英]Parallely running parameterized tests in pytest

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. 如果我们举这个简单的例子,我想运行所有4个test_even并行实例,然后移到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? 可以在pytest中做吗? I checked xdist, but could not find this type of support. 我检查了xdist,但找不到这种类型的支持。 Could anybody please give some pointers on how to implement this in pytest? 任何人都可以对如何在pytest中实现这一点提出一些建议吗?

Have a look at pytest-xdist it does a bunch of cool things, including allowing you to run your tests in parallel. 看看pytest-xdist它做了很多很酷的事情,包括允许您并行运行测试。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM