Create new dist option 'loadgroup'

This commit is contained in:
baekdohyeop
2021-11-29 00:03:49 +09:00
parent 6d83034bb8
commit 52a395888f
6 changed files with 203 additions and 1 deletions

View File

@@ -1326,6 +1326,115 @@ class TestFileScope:
assert c1 == c2
class TestGroupScope:
def test_by_module(self, testdir):
test_file = """
import pytest
class TestA:
@pytest.mark.xgroup(name="xgroup")
@pytest.mark.parametrize('i', range(5))
def test(self, i):
pass
"""
testdir.makepyfile(test_a=test_file, test_b=test_file)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestA", result.outlines
)
test_b_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_b.py::TestA", result.outlines
)
assert (
test_a_workers_and_test_count
in (
{"gw0": 5},
{"gw1": 0},
)
or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 5})
)
assert (
test_b_workers_and_test_count
in (
{"gw0": 5},
{"gw1": 0},
)
or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 5})
)
assert (
test_a_workers_and_test_count.items()
== test_b_workers_and_test_count.items()
)
def test_by_class(self, testdir):
testdir.makepyfile(
test_a="""
import pytest
class TestA:
@pytest.mark.xgroup(name="xgroup")
@pytest.mark.parametrize('i', range(10))
def test(self, i):
pass
class TestB:
@pytest.mark.xgroup(name="xgroup")
@pytest.mark.parametrize('i', range(10))
def test(self, i):
pass
"""
)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestA", result.outlines
)
test_b_workers_and_test_count = get_workers_and_test_count_by_prefix(
"test_a.py::TestB", result.outlines
)
assert (
test_a_workers_and_test_count
in (
{"gw0": 10},
{"gw1": 0},
)
or test_a_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
)
assert (
test_b_workers_and_test_count
in (
{"gw0": 10},
{"gw1": 0},
)
or test_b_workers_and_test_count in ({"gw0": 0}, {"gw1": 10})
)
assert (
test_a_workers_and_test_count.items()
== test_b_workers_and_test_count.items()
)
def test_module_single_start(self, testdir):
test_file1 = """
import pytest
@pytest.mark.xgroup(name="xgroup")
def test():
pass
"""
test_file2 = """
import pytest
def test_1():
pass
@pytest.mark.xgroup(name="xgroup")
def test_2():
pass
"""
testdir.makepyfile(test_a=test_file1, test_b=test_file1, test_c=test_file2)
result = testdir.runpytest("-n2", "--dist=loadgroup", "-v")
a = get_workers_and_test_count_by_prefix("test_a.py::test", result.outlines)
b = get_workers_and_test_count_by_prefix("test_b.py::test", result.outlines)
c = get_workers_and_test_count_by_prefix("test_c.py::test_2", result.outlines)
assert a.keys() == b.keys() and b.keys() == c.keys()
class TestLocking:
_test_content = """
class TestClassName%s(object):