Skip to content

Commit bd72c9f

Browse files
authored
TST: Add pytest-xdist to run tests in parallel (IMAP-Science-Operations-Center#1600)
* TST: Add pytest-xdist to run tests in parallel Make it opt-in but run the tests in parallel on the CI systems at least and allow users to locally use more processors.
1 parent 5e012f4 commit bd72c9f

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
run: |
4747
# Ignore the network marks from the remote test environment
4848
if [ "$USE_EXTERNAL_DATA" = "true" ]; then
49-
poetry run pytest --color=yes --cov --cov-report=xml
49+
poetry run pytest -n auto --color=yes --cov --cov-report=xml
5050
else
51-
poetry run pytest --color=yes --cov --cov-report=xml -m "not external_kernel and not external_test_data"
51+
poetry run pytest -n auto --color=yes --cov --cov-report=xml -m "not external_kernel and not external_test_data"
5252
fi
5353
5454
- name: Upload coverage reports to Codecov

imap_processing/tests/codice/test_codice_l1a.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from imap_processing.cdf.utils import load_cdf, write_cdf
1010
from imap_processing.codice import constants
1111
from imap_processing.codice.codice_l1a import process_codice_l1a
12+
from imap_processing.tests.conftest import _download_external_data, _test_data_paths
1213

1314
from .conftest import TEST_L0_FILE, VALIDATION_DATA
1415

@@ -112,7 +113,10 @@ def test_l1a_data() -> xr.Dataset:
112113
processed_datasets : list[xarray.Dataset]
113114
A list of ``xarray`` datasets containing the test data
114115
"""
115-
116+
# Make sure we have the data available here. This test collection gets
117+
# skipped at the module level if the mark isn't present. We can't decorate
118+
# a fixture, so add the needed call directly here instead.
119+
_download_external_data(_test_data_paths())
116120
processed_datasets = process_codice_l1a(file_path=TEST_L0_FILE)
117121

118122
return processed_datasets

imap_processing/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _download_external_kernels(spice_test_data_path):
9494

9595
@pytest.fixture(scope="session")
9696
def _download_test_data():
97-
_download_external_data(test_data_paths())
97+
_download_external_data(_test_data_paths())
9898

9999

100100
def _download_external_data(test_data_path_list):
@@ -125,7 +125,7 @@ def _download_external_data(test_data_path_list):
125125
logger.info(f"File already exists: {destination}")
126126

127127

128-
def test_data_paths():
128+
def _test_data_paths():
129129
"""Defines a list of test data files to download from the AWS S3 bucket
130130
and the corresponding location in which to store the downloaded file"""
131131
test_data_path_list = [

poetry.lock

Lines changed: 36 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pre-commit = {version="^3.3.3", optional=true}
4949
pydata-sphinx-theme = {version="*", optional=true}
5050
pytest = {version=">=6.2.5", optional=true}
5151
pytest-cov = {version="^4.0.0", optional=true}
52+
pytest-xdist = {version="^3.2", optional=true}
5253
ruff = {version="==0.2.1", optional=true}
5354
sphinx = {version="*", optional=true}
5455
sphinxcontrib-openapi = {version="^0.8.3", optional=true}
@@ -60,7 +61,7 @@ netcdf4 = {version ="^1.7.2", optional = true}
6061
[tool.poetry.extras]
6162
dev = ["pre-commit", "ruff", "mypy"]
6263
doc = ["numpydoc", "pydata-sphinx-theme", "sphinx", "sphinxcontrib-openapi"]
63-
test = ["openpyxl", "pytest", "pytest-cov", "requests", "netcdf4"]
64+
test = ["openpyxl", "pytest", "pytest-cov", "pytest-xdist", "requests", "netcdf4"]
6465
tools = ["openpyxl", "pandas"]
6566
map_visualization = ["healpy"]
6667

0 commit comments

Comments
 (0)