test_it.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pytest-randomly 作者: pytest-dev 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号