Ensure loadscope and loadfile work when the first scope has one work unit

This commit is contained in:
lmtierney
2018-02-08 19:38:18 -06:00
parent d91ec5503e
commit bd3c7dba8b
3 changed files with 69 additions and 0 deletions

1
changelog/257.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix issue when using ``loadscope`` or ``loadfile`` where tests would fail to start if the first scope had only one test.

View File

@@ -888,6 +888,38 @@ class TestLoadScope:
assert get_workers_and_test_count_by_prefix( assert get_workers_and_test_count_by_prefix(
'test_a.py::TestB', result.outlines) in ({'gw0': 10}, {'gw1': 10}) 'test_a.py::TestB', result.outlines) in ({'gw0': 10}, {'gw1': 10})
def test_module_single_start(self, testdir):
test_file1 = """
import pytest
def test():
pass
"""
test_file2 = """
import pytest
def test_1():
pass
def test_2():
pass
"""
testdir.makepyfile(
test_a=test_file1,
test_b=test_file1,
test_c=test_file2
)
result = testdir.runpytest('-n2', '--dist=loadscope', '-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)
c1 = get_workers_and_test_count_by_prefix('test_c.py::test_1',
result.outlines)
c2 = get_workers_and_test_count_by_prefix('test_c.py::test_2',
result.outlines)
assert a in ({'gw0': 1}, {'gw1': 1})
assert b in ({'gw0': 1}, {'gw1': 1})
assert a.items() != b.items()
assert c1 == c2
class TestFileScope: class TestFileScope:
@@ -943,6 +975,38 @@ class TestFileScope:
assert test_b_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \ assert test_b_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \
test_b_workers_and_test_count in ({'gw0': 0}, {'gw1': 10}) test_b_workers_and_test_count in ({'gw0': 0}, {'gw1': 10})
def test_module_single_start(self, testdir):
test_file1 = """
import pytest
def test():
pass
"""
test_file2 = """
import pytest
def test_1():
pass
def test_2():
pass
"""
testdir.makepyfile(
test_a=test_file1,
test_b=test_file1,
test_c=test_file2
)
result = testdir.runpytest('-n2', '--dist=loadfile', '-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)
c1 = get_workers_and_test_count_by_prefix('test_c.py::test_1',
result.outlines)
c2 = get_workers_and_test_count_by_prefix('test_c.py::test_2',
result.outlines)
assert a in ({'gw0': 1}, {'gw1': 1})
assert b in ({'gw0': 1}, {'gw1': 1})
assert a.items() != b.items()
assert c1 == c2
def parse_tests_and_workers_from_output(lines): def parse_tests_and_workers_from_output(lines):
result = [] result = []

View File

@@ -380,6 +380,10 @@ class LoadScopeScheduling:
for node in self.nodes: for node in self.nodes:
self._assign_work_unit(node) self._assign_work_unit(node)
# Ensure nodes start with at least two work units if possible
for node in self.nodes:
self._reschedule(node)
# Initial distribution sent all tests, start node shutdown # Initial distribution sent all tests, start node shutdown
if not self.workqueue: if not self.workqueue:
for node in self.nodes: for node in self.nodes: