def test_fixtures_dont_interfere_with_tests_getting_same_random_state(ourtestdir):
ourtestdir.makepyfile(
test_one="""
import random
import pytest
random.seed(2)
state_at_seed_two = random.getstate()
@pytest.fixture(scope='module')
def myfixture():
return random.random()
@pytest.mark.one()
def test_one(myfixture):
assert random.getstate() == state_at_seed_two
@pytest.mark.two()
def test_two(myfixture):
assert random.getstate() == state_at_seed_two
"""
)
args = ['--randomly-seed=2']
out = ourtestdir.runpytest(*args)
out.assert_outcomes(passed=2)
out = ourtestdir.runpytest('-m', 'one', *args)
out.assert_outcomes(passed=1)
out = ourtestdir.runpytest('-m', 'two', *args)
out.assert_outcomes(passed=1)
评论列表
文章目录