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

allow wildcard in asdf_schema_root #1756

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
4 changes: 4 additions & 0 deletions docs/asdf/extending/schemas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 35 additions & 24 deletions pytest_asdf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def _parse_test_list(content):


def pytest_collect_file(file_path, parent):
if file_path.suffix != ".yaml":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.yml is also commonly used, maybe we should let that one through as well?

return None

if not (parent.config.getini("asdf_schema_tests_enabled") or parent.config.getoption("asdf_tests")):
return None

Expand All @@ -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
Loading