Skip to content

Commit

Permalink
autotest: warn if sequential tests are not sent to same parallel worker
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Apr 18, 2024
1 parent 16ec4a5 commit 122cc14
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,36 @@ def pytest_collection_modifyitems(config, items):
)
)

# For any tests marked to run sequentially (pytest.mark.random_order(disabled=True)
# check to make sure they are also marked with pytest.mark.xdist_group()
# so they are sent to the same xdist worker.
unmarked_modules = set()
xdist = config.pluginmanager.getplugin("xdist")
if xdist and xdist.is_xdist_worker(item.session):
for mark in item.iter_markers("random_order"):
if (
mark.kwargs["disabled"]
and not next(item.iter_markers("xdist_group"), None)
and item.module.__name__ not in unmarked_modules
):
unmarked_modules.add(item.module.__name__)
import warnings

warnings.warn(
f"module {item.module.__name__} marked as random_order(disabled=True) but does not have an assigned xdist_group"
)


def pytest_addoption(parser):
parser.addini("gdal_version", "GDAL version for which pytest.ini was generated")

# our pytest.ini specifies --dist=loadgroup but we don't want to fail if the
# user doesn't have this extension installed.
try:
import xdist # noqa: F401
except ImportError:
parser.addoption("--dist")


def pytest_configure(config):
test_version = config.getini("gdal_version")
Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gdaltindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
reason="gdaltindex not available",
),
pytest.mark.random_order(disabled=True),
pytest.mark.xdist_group("test_gdaltindex"),
]


Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gnmutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
reason="gnmanalyse not available",
),
pytest.mark.random_order(disabled=True),
pytest.mark.xdist_group("test_gnmutils"),
]


Expand Down
6 changes: 5 additions & 1 deletion cmake/template/pytest.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ markers =
require_proj: Skip test(s) if required PROJ version is not available
require_run_on_demand: Skip test(s) if RUN_ON_DEMAND environment variable is not set
slow: Skip test(s) if GDAL_RUN_SLOW_TESTS environment variable is not set
xdist_group: Associated test with a named group that will be sent to a single parallel worker

# Make sure that all markers are declared above
addopts = --strict-markers
# --strict-markers causes an error if a test has a marker that is not handled
# --dist=loadgroup instructs pytest-xdist to send tests marked with the same
# xdist_group marker to the same worker.
addopts = --strict-markers --dist=loadgroup

0 comments on commit 122cc14

Please sign in to comment.