climate_ref.conftest_plugin
#
Pytest plugin providing shared fixtures for diagnostic provider testing.
This plugin is registered as climate_ref in the pytest11 entry point group.
Provider packages can use these fixtures by adding climate-ref[test] to their
test dependencies.
Usage in a provider's conftest.py::
pytest_plugins = ("climate_ref.conftest_plugin",)
Or install climate-ref[test] and the plugin is auto-discovered.
Provided fixtures
config-- per-testConfigwith isolated directoriescaplog-- loguru-compatible log capturetest_data_dir/sample_data_dir/regression_data_dir-- data pathssample_data-- session-scoped sample data fetchcmip6_data_catalog/obs4mips_data_catalog/data_catalog-- data catalogsrun_test_case--TestCaseRunnerwrapper that converts errors topytest.skipdefinition_factory-- createExecutionDefinitioninstancesprovider/mock_diagnostic-- mock diagnostic providerexecution_regression-- regression output managementdiagnostic_validation-- legacy validation helperinvoke_cli-- CLI test runner
DiagnosticValidator
#
Validator for running diagnostics with sample data.
.. deprecated::
Use RegressionValidator from climate_ref_core.testing instead.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
execute(definition)
#
Run the diagnostic and optionally save regression data.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
get_definition()
#
Build an execution definition from the data catalog.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
get_regression_definition()
#
Load regression data and build an execution definition.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
validate(definition)
#
Validate CMEC bundles and series, and store the execution result.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
ExecutionRegression
#
Copy execution output to the test-data directory for regression testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
check(key, output_directory)
#
Check and optionally regenerate regression data.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
hydrate_output_directory(output_dir, replacements)
#
Replace any references to the placeholder with the actual output directory.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
output_replacements(output_directory)
#
Map real paths to regression placeholders for a given output directory.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
path(key)
#
Return the regression data path for the given key.
replace_references(output_dir, replacements)
#
Replace any references to local directories with a placeholder.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
FailedDiagnostic
#
Bases: Diagnostic
A diagnostic that always fails, for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
run(definition)
#
Run a diagnostic that always returns a failure result.
MockDiagnostic
#
Bases: Diagnostic
A no-op diagnostic for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
run(definition)
#
Run a no-op diagnostic that always succeeds.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
caplog(caplog)
#
Capture logs from the loguru default logger.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
cleanup_log_handlers(request)
#
Remove any dangling loguru handlers after each test.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
cmip6_data_catalog(sample_data, sample_data_dir)
#
CMIP6 sample data catalog.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
config(tmp_path, monkeypatch, request)
#
Per-test Config with isolated directories.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
data_catalog(cmip6_data_catalog, obs4mips_data_catalog)
#
Provide combined data catalog with CMIP6 and obs4MIPs sources.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
definition_factory(tmp_path, config)
#
Create ExecutionDefinition instances for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
diagnostic_validation(config, mocker, provider, data_catalog, execution_regression)
#
Create DiagnosticValidator instances for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
esgf_data_catalog(esgf_solve_catalog, test_data_dir)
#
ESGF metadata catalog for tests that only need DataFrames, not actual files.
Uses pre-generated parquet catalogs from tests/test-data/esgf-catalog/.
Fails if the catalog is not available (run scripts/generate_esgf_catalog.py).
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
esgf_data_catalog_trimmed(esgf_solve_catalog, test_data_dir)
#
Trimmed ESGF catalog for integration tests.
Uses a fixed set of CMIP6 source_ids to keep the catalog small and tests fast, while still covering multiple models.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
esgf_solve_catalog(test_data_dir)
#
Load ESGF metadata catalog for solve tests, if available.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
execution_regression(request, regression_data_dir, test_data_dir)
#
Create ExecutionRegression instances for a diagnostic.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
invoke_cli(config, monkeypatch)
#
Invoke the REF CLI and verify exit code.
Depends on the config fixture so every CLI invocation uses an
isolated configuration directory and database rather than the user's
real one.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
metric_definition(definition_factory, cmip6_data_catalog, mock_diagnostic)
#
Create an ExecutionDefinition with a selected CMIP6 dataset for metric tests.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
mock_diagnostic(provider)
#
Return the mock diagnostic from the mock provider.
obs4mips_data_catalog(sample_data, sample_data_dir)
#
obs4MIPs sample data catalog.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
provider(tmp_path, config)
#
Create a mock provider with mock and failed diagnostics registered.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
pytest_addoption(parser)
#
Add custom CLI options.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
pytest_collection_modifyitems(config, items)
#
Skip slow/docker tests unless opted in.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
pytest_configure(config)
#
Register custom markers.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
regression_data_dir(test_data_dir)
#
run_test_case(config)
#
Fixture for running diagnostic test cases.
Wraps TestCaseRunner to convert TestCaseError into pytest.skip.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
sample_data()
#
Download sample data if not already present.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
sample_data_dir(test_data_dir)
#
solve_config()
#
Session-scoped Config that uses the local default_ignore_datasets.yaml
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
test_data_dir()
#
Path to the centralised test data directory.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
tmp_path_session()
#
Session-scoped temporary directory.