Py.test With Xdist Is Not Executing Tests Parametrized With Random Values
Solution 1:
So here is the code after Armins hint :)
import pytest
import random
PARAMS_NUMBER = 3
PARAMS = []
for i inrange(PARAMS_NUMBER):
PARAMS.append(1000)
@pytest.mark.parametrize('rand_par', PARAMS)deftest_random_param(rand_par):
par_val = random.randrange(0, rand_par)
assert500 > par_val
And it runs test 3 times with randomly selected value.
Update: I have created an issue for xdist project and it is resolved in the meaning of returning reasonable info for user.
More info can be found here py.test with xdist is not executing tests parametrized with random values
Solution 2:
A workaround would be to parametrize with reproducible (but meaningless) values, like all numbers between 0 and PARAMS_NUMBER-1
. Then each test can individually pick a random value when it runs. In order to know which random value it picked (to reproduce in case of crash), each test should print it first. At least that's what I do with some non-xdist tests; I hope it works too with xdist, i.e. the prints are correctly propagated to the parent process and only shown if the individual test fails (or py.test is run with -s).
Post a Comment for "Py.test With Xdist Is Not Executing Tests Parametrized With Random Values"