Skip to content

Commit 1d1d1a6

Browse files
Patrick JordanPatrickJordanNutanix
Patrick Jordan
authored andcommitted
Override workers when number of tests to execute is less
A number of pytest sessions are hanging at the end and it is not 100% clear what the cause is. However, some experimentation with the number of workers and tests to execute has shown: - When they exceed the number of tests to execute, the hang at the end of the pytest session is more likely to occur - When they are equal to or less than the tests to execute, the hang has yet to occur Therefore, this speculative fix overrides the `workers` to be the number of tests to execute when it exceeds the originally configured number.
1 parent 76bcb8f commit 1d1d1a6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pytest_parallel/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ def pytest_runtestloop(self, session):
246246

247247
if session.config.option.collectonly:
248248
return True
249+
250+
# Override the number of workers based on the number of tests being
251+
# executed if it is less than what was originally configured. This
252+
# is a speculative fix to avoid pytest from hanging when more workers
253+
# are spawned than is needed by the number of tests being executed.
254+
if self.workers > len(session.items):
255+
self.workers = len(session.items)
249256

250257
# get the number of tests per worker
251258
tests_per_worker = parse_config(session.config, 'tests_per_worker')

0 commit comments

Comments
 (0)