带有xdist的py.test没有执行参数化为随机值的测试 [英] py.test with xdist is not executing tests parametrized with random values
问题描述
有人注意到pytest和xdist有以下奇怪行为吗?
Does anybody noticed the following strange behaviour for pytest and xdist.
当尝试运行由一些随机选择的值参数化的测试时,实际上不会运行该测试. 如果不使用xdist,则执行相同的测试不会有任何问题.
When trying to run the test that is parametrized with some randomly selected values the test are not actualy run. The same test is executed without any problems if xdist is not used.
以下代码可用于重现此代码.
Following code can be used to reproduce this.
import pytest
import random
PARAMS_NUMBER = 3
PARAMS = []
for i in range(PARAMS_NUMBER):
PARAMS.append(random.randrange(0, 1000))
@pytest.mark.parametrize('rand_par', PARAMS)
def test_random_param(rand_par):
assert 500 > rand_par
没有xdists可以正常工作.
Without xdists it works fine.
对于xdist,使用以下输出完全不执行测试
With xdist no test is executed at all with the following output
============================= test session starts =============================
platform win32 -- Python 2.7.3 -- py-1.4.24 -- pytest-2.6.2
plugins: xdist
gw0 [3] / gw1 [3] / gw2 [3] / gw3 [3]
scheduling tests via LoadScheduling
============================== in 1.93 seconds ===============================
我正在使用的版本:
- python 2.7.3
- pytest 2.6.2
- pytest-xdist 1.11
附加说明:
对于某些较旧的版本(xdist 1.8和pytest 2.4.X或2.5.X不能完全记住),xdist会在dsession.py中断言停止
With some older versions (xdist 1.8 and pytest 2.4.X or 2.5.X do not remember exactly) the xdist was stopping on assertion in dsession.py
assert collection == col
在此先感谢您提供帮助,以解决问题,或者至少可以解决该问题:)
Thanks in advance for any help how to solve it or at least workaround it :)
推荐答案
所以这是Armins提示后的代码:)
So here is the code after Armins hint :)
import pytest
import random
PARAMS_NUMBER = 3
PARAMS = []
for i in range(PARAMS_NUMBER):
PARAMS.append(1000)
@pytest.mark.parametrize('rand_par', PARAMS)
def test_random_param(rand_par):
par_val = random.randrange(0, rand_par)
assert 500 > par_val
它以随机选择的值运行了3次测试.
And it runs test 3 times with randomly selected value.
更新: 我已经为xdist项目创建了一个问题,并且已解决了为用户返回合理信息的问题.
Update: I have created an issue for xdist project and it is resolved in the meaning of returning reasonable info for user.
更多信息可在此处找到带有xdist的py.test没有执行参数化为随机值的测试
More info can be found here py.test with xdist is not executing tests parametrized with random values
这篇关于带有xdist的py.test没有执行参数化为随机值的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!