@@ -9,11 +9,19 @@ def twenty_tests():
99 return '' .join (code )
1010
1111
12- @pytest .mark .parametrize ('disabled' , [True ])
13- def test_pytest_mark_random_order_disabled (testdir , twenty_tests , get_test_calls , disabled ):
12+ @pytest .fixture
13+ def twenty_cls_tests ():
14+ code = []
15+ for i in range (20 ):
16+ code .append ('\t def test_b{}(self): self.assertTrue\n ' .format (str (i ).zfill (2 )))
17+ return '' .join (code )
18+
19+
20+ @pytest .mark .parametrize ('disabled' , [True , False ])
21+ def test_marker_disables_random_order_in_module (testdir , twenty_tests , get_test_calls , disabled ):
1422 testdir .makepyfile (
1523 'import pytest\n ' +
16- ' pytest.mark.random_order_disabled = {} \n ' .format (disabled ) +
24+ ( 'pytestmark = pytest.mark.random_order(disabled={}) \n ' .format (disabled ) ) +
1725 twenty_tests
1826 )
1927
@@ -26,3 +34,24 @@ def test_pytest_mark_random_order_disabled(testdir, twenty_tests, get_test_calls
2634 assert names == sorted_names
2735 else :
2836 assert names != sorted_names
37+
38+
39+ @pytest .mark .parametrize ('disabled' , [True , False ])
40+ def test_marker_disables_random_order_in_class (testdir , twenty_cls_tests , get_test_calls , disabled ):
41+ testdir .makepyfile (
42+ 'import pytest\n \n ' +
43+ 'from unittest import TestCase\n \n ' +
44+ 'class MyTest(TestCase):\n ' +
45+ '\t pytestmark = pytest.mark.random_order(disabled={})\n ' .format (disabled ) +
46+ twenty_cls_tests + '\n '
47+ )
48+
49+ result = testdir .runpytest ('--random-order-bucket=module' , '-v' )
50+ result .assert_outcomes (passed = 20 )
51+ names = [c .name for c in get_test_calls (testdir .runpytest ())]
52+ sorted_names = sorted (list (names ))
53+
54+ if disabled :
55+ assert names == sorted_names
56+ else :
57+ assert names != sorted_names
0 commit comments