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-- data pathssample_data-- session-scoped sample data fetchcmip6_data_catalog/obs4mips_data_catalog/data_catalog-- data catalogsdefinition_factory-- createExecutionDefinitioninstancesprovider/mock_diagnostic-- mock diagnostic providersolved_definition_factory-- build anExecutionDefinitionfrom the sample-data cataloginvoke_cli-- CLI test runner
FailedDiagnostic
#
Bases: Diagnostic
A diagnostic that always fails, for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
run(definition, *, capture_regression=False)
#
Run a diagnostic that always returns a failure result.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
MockDiagnostic
#
Bases: Diagnostic
A no-op diagnostic for testing.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
run(definition, *, capture_regression=False)
#
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
catalog_pid_parser(file, **kwargs)
#
Record the PID of the process that parsed file (proves out-of-process runs).
catalog_reject_txt_parser(file, **kwargs)
#
Like :func:catalog_stub_parser but marks .txt files invalid.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
catalog_stub_parser(file, **kwargs)
#
Return trivial valid metadata for file without opening it.
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
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
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
packaged_ignore_datasets_file()
#
Locate the default_ignore_datasets.yaml shipped inside the climate_ref package.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the packaged ignore datasets file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is missing from the installed package. |
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
sample_data()
#
Download sample data if not already present.
Source code in packages/climate-ref/src/climate_ref/conftest_plugin.py
sample_data_dir(sample_data, test_data_dir)
#
Path to the sample data directory.
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
solved_definition_factory(config, mocker, data_catalog)
#
Build an ExecutionDefinition by solving a diagnostic against the sample-data catalog.
Returns a factory that solves the first execution for the given diagnostic and builds
its definition under the test scratch directory. Useful for unit tests that need a
realistic definition without running the diagnostic (e.g. to inspect the commands it
would build).
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.