Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix failing build #447

Merged
merged 10 commits into from
Oct 21, 2024
1 change: 1 addition & 0 deletions changelog/447.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix failure to fetch CLI options in publish build.
11 changes: 9 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import matplotlib as mpl
import pytest

Expand Down Expand Up @@ -28,8 +30,13 @@ def pytest_report_header(config, start_path):
def pytest_runtest_makereport(item, call):
report = yield
if report.when == "call":
ds = item.config.getoption("--ds")
tds = item.config.getoption("--tiled-ds")
try:
ds = item.config.getoption("--ds")
tds = item.config.getoption("--tiled-ds")
except ValueError:
# If CLI arguments can't be found, need to return gracefully
warnings.warn("--ds and --tiled-ds were not found. Any supplied datasets were not used.")
return report
if ds and item.get_closest_marker("accept_cli_dataset"):
report.nodeid += f"[{ds}]"
if tds and item.get_closest_marker("accept_cli_tiled_dataset"):
Expand Down
35 changes: 21 additions & 14 deletions dkist/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import gzip
import warnings
from pathlib import Path

import dask.array as da
Expand Down Expand Up @@ -351,17 +352,23 @@ def visp_dataset_no_headers(tmp_path_factory):

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
ds = item.config.getoption("--ds")
tds = item.config.getoption("--tiled-ds")

# Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available
mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset")
if mark:
# Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition
replace_arg = mark.args[0] if mark.args else item.fixturenames[0]
if ds:
item.funcargs[replace_arg] = load_dataset(ds)
if tds:
item.funcargs[replace_arg] = load_dataset(tds)

yield item
try:
ds = item.config.getoption("--ds")
tds = item.config.getoption("--tiled-ds")

# Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available
mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset")
if mark:
# Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition
replace_arg = mark.args[0] if mark.args else item.fixturenames[0]
if ds:
item.funcargs[replace_arg] = load_dataset(ds)
if tds:
item.funcargs[replace_arg] = load_dataset(tds)

yield item
except ValueError:
# If CLI arguments can't be found, need to return gracefully
# TODO raise a warning here
warnings.warn("--ds and --tiled-ds were not found. Any supplied datasets will not be used.")
yield item