From 1181703374e03cf8bc99295f166d835d996ebb7b Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 14 Feb 2024 11:37:49 -0500 Subject: [PATCH 1/3] allow wildcard in asdf_schema_root --- pytest_asdf/plugin.py | 59 +++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/pytest_asdf/plugin.py b/pytest_asdf/plugin.py index bccdf3e8a..12c64d280 100644 --- a/pytest_asdf/plugin.py +++ b/pytest_asdf/plugin.py @@ -276,6 +276,9 @@ def _parse_test_list(content): def pytest_collect_file(file_path, parent): + if file_path.suffix != ".yaml": + return None + if not (parent.config.getini("asdf_schema_tests_enabled") or parent.config.getoption("asdf_tests")): return None @@ -292,32 +295,40 @@ def pytest_collect_file(file_path, parent): skip_tests = _parse_test_list(parent.config.getini("asdf_schema_skip_tests")) xfail_tests = _parse_test_list(parent.config.getini("asdf_schema_xfail_tests")) - schema_roots = [os.path.join(str(parent.config.rootpath), os.path.normpath(root)) for root in schema_roots] - - if file_path.suffix != ".yaml": + if file_path.stem in skip_names: return None + resolved_schema_roots = [] for root in schema_roots: - if str(file_path).startswith(root) and file_path.stem not in skip_names: - posix_path = pathlib.Path(file_path).as_posix() - schema_skip_tests = [] - for suffix, names in skip_tests.items(): - if posix_path.endswith(suffix): - schema_skip_tests.extend(names) - schema_xfail_tests = [] - for suffix, names in xfail_tests.items(): - if posix_path.endswith(suffix): - schema_xfail_tests.extend(names) - - return AsdfSchemaFile.from_parent( - parent, - fspath=file_path, - skip_examples=(file_path.stem in skip_examples), - validate_default=validate_default, - ignore_unrecognized_tag=ignore_unrecognized_tag, - ignore_version_mismatch=ignore_version_mismatch, - skip_tests=schema_skip_tests, - xfail_tests=schema_xfail_tests, - ) + if not root.startswith("*"): + root = os.path.join(str(parent.config.rootpath), os.path.normpath(root)) + resolved_schema_roots.append(root) + + for root in resolved_schema_roots: + if root.startswith("*"): + if root.strip("*") not in str(file_path): + continue + elif not str(file_path).startswith(root): + continue + posix_path = pathlib.Path(file_path).as_posix() + schema_skip_tests = [] + for suffix, names in skip_tests.items(): + if posix_path.endswith(suffix): + schema_skip_tests.extend(names) + schema_xfail_tests = [] + for suffix, names in xfail_tests.items(): + if posix_path.endswith(suffix): + schema_xfail_tests.extend(names) + + return AsdfSchemaFile.from_parent( + parent, + fspath=file_path, + skip_examples=(file_path.stem in skip_examples), + validate_default=validate_default, + ignore_unrecognized_tag=ignore_unrecognized_tag, + ignore_version_mismatch=ignore_version_mismatch, + skip_tests=schema_skip_tests, + xfail_tests=schema_xfail_tests, + ) return None From 875ffed9c8d9df2416e0d6ed34407146d7c3df3f Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 14 Feb 2024 11:49:03 -0500 Subject: [PATCH 2/3] add changelog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9b7e451c1..438e07715 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,6 +24,10 @@ resolve to public classes (even if the class is implemented in a private module). [#1654] +- Allow use of a starting wildcard in the ``asdf_schema_root`` setting + for the asdf pytest plugin to allow schemas to be collected during + ``--pyargs`` test runs [#1756] + 3.2.0 (2024-04-05) ------------------ From fb88c920048e0090b153404f232309f5a3ffedc8 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 14 Feb 2024 11:51:44 -0500 Subject: [PATCH 3/3] update docs --- docs/asdf/extending/schemas.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/asdf/extending/schemas.rst b/docs/asdf/extending/schemas.rst index a1d9f9d66..901b1bf26 100644 --- a/docs/asdf/extending/schemas.rst +++ b/docs/asdf/extending/schemas.rst @@ -276,6 +276,10 @@ package directory **when it is installed**. If this is different from the path in the source directory, then both paths can be used to facilitate in-place testing (see `asdf`'s own ``pyproject.toml`` for an example of this). +The ``asdf_schema_root`` may also start with a "wildcard" (``*``) which will cause +the plugin to match any path that contains the ``asdf_schema_root`` setting (without +the wildcard). + .. note:: Older versions of `asdf` (prior to 2.4.0) required the plugin to be registered