Add --no-loadscope-reorder and --loadscope-reorder options (#1217)
Based on #1098. Closes #1098 --------- Co-authored-by: Toan Vuong <toan.vuong@hyperscience.com>
This commit is contained in:
@@ -127,6 +127,32 @@ def pytest_addoption(parser: pytest.Parser) -> None:
|
||||
"(default) no: Run tests inprocess, don't distribute."
|
||||
),
|
||||
)
|
||||
group.addoption(
|
||||
"--loadscope-reorder",
|
||||
dest="loadscopereorder",
|
||||
action="store_true",
|
||||
default=True,
|
||||
help=(
|
||||
"Pytest-xdist will default reorder tests by number of tests per scope "
|
||||
"when used in conjunction with loadscope.\n"
|
||||
"This option will enable loadscope reorder which will improve the "
|
||||
"parallelism of the test suite.\n"
|
||||
"However, the partial order of tests might not be retained.\n"
|
||||
),
|
||||
)
|
||||
group.addoption(
|
||||
"--no-loadscope-reorder",
|
||||
dest="loadscopereorder",
|
||||
action="store_false",
|
||||
help=(
|
||||
"Pytest-xdist will default reorder tests by number of tests per scope "
|
||||
"when used in conjunction with loadscope.\n"
|
||||
"This option will disable loadscope reorder, "
|
||||
"and the partial order of tests can be retained.\n"
|
||||
"This is useful when pytest-xdist is used together with "
|
||||
"other plugins that specify tests in a specific order."
|
||||
),
|
||||
)
|
||||
group.addoption(
|
||||
"--tx",
|
||||
dest="tx",
|
||||
|
||||
@@ -371,11 +371,15 @@ class LoadScopeScheduling:
|
||||
work_unit = unsorted_workqueue.setdefault(scope, {})
|
||||
work_unit[nodeid] = False
|
||||
|
||||
# Insert tests scopes into work queue ordered by number of tests.
|
||||
for scope, nodeids in sorted(
|
||||
unsorted_workqueue.items(), key=lambda item: -len(item[1])
|
||||
):
|
||||
self.workqueue[scope] = nodeids
|
||||
if self.config.option.loadscopereorder:
|
||||
# Insert tests scopes into work queue ordered by number of tests.
|
||||
for scope, nodeids in sorted(
|
||||
unsorted_workqueue.items(), key=lambda item: -len(item[1])
|
||||
):
|
||||
self.workqueue[scope] = nodeids
|
||||
else:
|
||||
for scope, nodeids in unsorted_workqueue.items():
|
||||
self.workqueue[scope] = nodeids
|
||||
|
||||
# Avoid having more workers than work
|
||||
extra_nodes = len(self.nodes) - len(self.workqueue)
|
||||
|
||||
Reference in New Issue
Block a user