@@ -1326,6 +1326,134 @@ def test_2():
13261326 assert c1 == c2
13271327
13281328
1329+ class TestGroupScope :
1330+ def test_by_module (self , testdir ):
1331+ test_file = """
1332+ import pytest
1333+ class TestA:
1334+ @pytest.mark.xdist_group(name="xdist_group")
1335+ @pytest.mark.parametrize('i', range(5))
1336+ def test(self, i):
1337+ pass
1338+ """
1339+ testdir .makepyfile (test_a = test_file , test_b = test_file )
1340+ result = testdir .runpytest ("-n2" , "--dist=loadgroup" , "-v" )
1341+ test_a_workers_and_test_count = get_workers_and_test_count_by_prefix (
1342+ "test_a.py::TestA" , result .outlines
1343+ )
1344+ test_b_workers_and_test_count = get_workers_and_test_count_by_prefix (
1345+ "test_b.py::TestA" , result .outlines
1346+ )
1347+
1348+ assert (
1349+ test_a_workers_and_test_count
1350+ in (
1351+ {"gw0" : 5 },
1352+ {"gw1" : 0 },
1353+ )
1354+ or test_a_workers_and_test_count in ({"gw0" : 0 }, {"gw1" : 5 })
1355+ )
1356+ assert (
1357+ test_b_workers_and_test_count
1358+ in (
1359+ {"gw0" : 5 },
1360+ {"gw1" : 0 },
1361+ )
1362+ or test_b_workers_and_test_count in ({"gw0" : 0 }, {"gw1" : 5 })
1363+ )
1364+ assert (
1365+ test_a_workers_and_test_count .items ()
1366+ == test_b_workers_and_test_count .items ()
1367+ )
1368+
1369+ def test_by_class (self , testdir ):
1370+ testdir .makepyfile (
1371+ test_a = """
1372+ import pytest
1373+ class TestA:
1374+ @pytest.mark.xdist_group(name="xdist_group")
1375+ @pytest.mark.parametrize('i', range(10))
1376+ def test(self, i):
1377+ pass
1378+ class TestB:
1379+ @pytest.mark.xdist_group(name="xdist_group")
1380+ @pytest.mark.parametrize('i', range(10))
1381+ def test(self, i):
1382+ pass
1383+ """
1384+ )
1385+ result = testdir .runpytest ("-n2" , "--dist=loadgroup" , "-v" )
1386+ test_a_workers_and_test_count = get_workers_and_test_count_by_prefix (
1387+ "test_a.py::TestA" , result .outlines
1388+ )
1389+ test_b_workers_and_test_count = get_workers_and_test_count_by_prefix (
1390+ "test_a.py::TestB" , result .outlines
1391+ )
1392+
1393+ assert (
1394+ test_a_workers_and_test_count
1395+ in (
1396+ {"gw0" : 10 },
1397+ {"gw1" : 0 },
1398+ )
1399+ or test_a_workers_and_test_count in ({"gw0" : 0 }, {"gw1" : 10 })
1400+ )
1401+ assert (
1402+ test_b_workers_and_test_count
1403+ in (
1404+ {"gw0" : 10 },
1405+ {"gw1" : 0 },
1406+ )
1407+ or test_b_workers_and_test_count in ({"gw0" : 0 }, {"gw1" : 10 })
1408+ )
1409+ assert (
1410+ test_a_workers_and_test_count .items ()
1411+ == test_b_workers_and_test_count .items ()
1412+ )
1413+
1414+ def test_module_single_start (self , testdir ):
1415+ test_file1 = """
1416+ import pytest
1417+ @pytest.mark.xdist_group(name="xdist_group")
1418+ def test():
1419+ pass
1420+ """
1421+ test_file2 = """
1422+ import pytest
1423+ def test_1():
1424+ pass
1425+ @pytest.mark.xdist_group(name="xdist_group")
1426+ def test_2():
1427+ pass
1428+ """
1429+ testdir .makepyfile (test_a = test_file1 , test_b = test_file1 , test_c = test_file2 )
1430+ result = testdir .runpytest ("-n2" , "--dist=loadgroup" , "-v" )
1431+ a = get_workers_and_test_count_by_prefix ("test_a.py::test" , result .outlines )
1432+ b = get_workers_and_test_count_by_prefix ("test_b.py::test" , result .outlines )
1433+ c = get_workers_and_test_count_by_prefix ("test_c.py::test_2" , result .outlines )
1434+
1435+ assert a .keys () == b .keys () and b .keys () == c .keys ()
1436+
1437+ def test_with_two_group_names (self , testdir ):
1438+ test_file = """
1439+ import pytest
1440+ @pytest.mark.xdist_group(name="group1")
1441+ def test_1():
1442+ pass
1443+ @pytest.mark.xdist_group("group2")
1444+ def test_2():
1445+ pass
1446+ """
1447+ testdir .makepyfile (test_a = test_file , test_b = test_file )
1448+ result = testdir .runpytest ("-n2" , "--dist=loadgroup" , "-v" )
1449+ a_1 = get_workers_and_test_count_by_prefix ("test_a.py::test_1" , result .outlines )
1450+ a_2 = get_workers_and_test_count_by_prefix ("test_a.py::test_2" , result .outlines )
1451+ b_1 = get_workers_and_test_count_by_prefix ("test_b.py::test_1" , result .outlines )
1452+ b_2 = get_workers_and_test_count_by_prefix ("test_b.py::test_2" , result .outlines )
1453+
1454+ assert a_1 .keys () == b_1 .keys () and a_2 .keys () == b_2 .keys ()
1455+
1456+
13291457class TestLocking :
13301458 _test_content = """
13311459 class TestClassName%s(object):
0 commit comments