ACCESS-NRI / access-nri-intake-catalog

Tools and configuration info used to manage ACCESS-NRI's intake catalogue
https://access-nri-intake-catalog.rtfd.io
Apache License 2.0
8 stars 1 forks source link

[BUG] CLI tests will fail if not executed from top-level directory #265

Closed marc-white closed 50 minutes ago

marc-white commented 5 days ago

Describe the bug

If the test suite is executed via pytest from anywhere other than the top-level directory of the package, all of the test_cli.py tests will error out with FileNotFoundError:

FAILED test_cli.py::test_build[v2024-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build[2024-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_bad_metadata - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata-bad.yaml'
FAILED test_cli.py::test_build_repeat_nochange - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_adddata - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data[v2001-01-01-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data[None-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data[v2001-01-01-None] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data_existing_old_cat[v2001-01-01-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data_existing_old_cat[None-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_existing_data_existing_old_cat[v2001-01-01-None] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_renamecatalogyaml[v2001-01-01-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_renamecatalogyaml[None-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_renamecatalogyaml[v2001-01-01-None] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct[v2001-01-01-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct[None-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct[v2001-01-01-None] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct_multivers[v2001-01-01-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct_multivers[None-v2099-01-01] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'
FAILED test_cli.py::test_build_repeat_altercatalogstruct_multivers[v2001-01-01-None] - FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/access-om2/metadata.yaml'

To Reproduce

Attempt to run pytest from, e.g., inside the tests directory of the package, rather than at the top level.

Additional context

I think the issue is coming from the paths within the test catalog YAML configs being hard-coded with respect to the top-level package directory, e.g., in tests/data/config/access-om2.yaml:

builder: AccessOm2Builder

translator: DefaultTranslator

sources:

  - path:
      - tests/data/access-om2
    metadata_yaml: tests/data/access-om2/metadata.yaml

I'm not sure how to fix this yet - we'd need to intercept the read of these YAML files and prepend the absolute test path somehow (via mock or otherwise).