@@ -1367,6 +1367,52 @@ def test2(self):
13671367 assert len (counts_by_worker_fence_b ) == 1
13681368 assert next (iter (counts_by_worker_fence_b .values ())) == 2
13691369
1370+ @pytest .mark .parametrize ('num_tests' , [1 , 2 , 3 , 4 , 5 , 7 ])
1371+ def test_two_tests_min_per_worker_rule_with_two_workers (
1372+ self , num_tests : int , pytester : pytest .Pytester
1373+ ) -> None :
1374+ """
1375+ isoscope allocates at least two tests per worker from the active scope,
1376+ unless the scope has only one test.
1377+ """
1378+ test_file1 = f"""
1379+ import pytest
1380+ # 6 tests should distribute 2 per worker for 3 workers due to the
1381+ # min-2 scope tests per worker rule.
1382+ @pytest.mark.parametrize('i', range({ num_tests } ))
1383+ def test(i):
1384+ pass
1385+ """
1386+ pytester .makepyfile (test_a = test_file1 )
1387+ result = pytester .runpytest ("-n2" , "--dist=isoscope" , "-v" )
1388+
1389+ if num_tests == 1 :
1390+ expected_worker_a_test_count = 1
1391+ elif num_tests == 2 :
1392+ expected_worker_a_test_count = 2
1393+ elif num_tests == 3 :
1394+ expected_worker_a_test_count = 3
1395+ elif num_tests == 4 :
1396+ expected_worker_a_test_count = 2
1397+ elif num_tests == 5 :
1398+ expected_worker_a_test_count = 3
1399+ elif num_tests == 7 :
1400+ expected_worker_a_test_count = 4
1401+ else :
1402+ assert False , f"Unexpected { num_tests = } "
1403+
1404+ counts_by_worker_a = get_workers_and_test_count_by_prefix (
1405+ "test_a.py::test" , result .outlines
1406+ )
1407+
1408+ counts_by_worker_a .setdefault ("gw0" , 0 )
1409+ counts_by_worker_a .setdefault ("gw1" , 0 )
1410+
1411+ assert set (counts_by_worker_a .values ()) == {
1412+ expected_worker_a_test_count ,
1413+ num_tests - expected_worker_a_test_count
1414+ }
1415+
13701416
13711417class TestLoadScope :
13721418 def test_by_module (self , pytester : pytest .Pytester ) -> None :
0 commit comments