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

Fix for pytest 7.0 depreciation warning #1075

Merged
merged 4 commits into from
Feb 4, 2022
Merged
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
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.9.2 (unreleased)
------------------

- Fix deprecation warnings stemming from the release of pytest 7.0.0. [#1075]

2.9.1 (2022-02-03)
------------------

Expand Down
14 changes: 9 additions & 5 deletions asdf/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,18 @@ def assert_no_warnings(warning_class=None):
emitted.
"""
import pytest
with pytest.warns(None) as recorded_warnings:
yield

if warning_class is not None:
if warning_class is None:
with warnings.catch_warnings():
warnings.simplefilter("error")

yield
else:
with pytest.warns(Warning) as recorded_warnings:
yield

assert not any(isinstance(w.message, warning_class) for w in recorded_warnings), \
display_warnings(recorded_warnings)
else:
assert len(recorded_warnings) == 0, display_warnings(recorded_warnings)


def assert_extension_correctness(extension):
Expand Down
2 changes: 1 addition & 1 deletion asdf/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_undefined_tag():
- !core/complex-1.0.0 3.14j
"""
buff = helpers.yaml_to_asdf(yaml)
with pytest.warns(None) as warning:
with pytest.warns(Warning) as warning:
afile = asdf.open(buff)
missing = afile.tree['undefined_data']

Expand Down
22 changes: 17 additions & 5 deletions pytest_asdf/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import warnings
from importlib.util import find_spec
from pkg_resources import parse_version
import pathlib
Expand Down Expand Up @@ -58,10 +59,20 @@ class AsdfSchemaFile(pytest.File):
@classmethod
def from_parent(cls, parent, *, fspath, skip_examples=False, validate_default=True,
ignore_unrecognized_tag=False, ignore_version_mismatch=False, skip_tests=[], xfail_tests=[], **kwargs):

# Fix for depreciation of fspath in pytest 7+
from asdf.util import minversion
if minversion("pytest", "7.0.0"):
path = pathlib.Path(fspath)
kwargs["path"] = path
else:
path = fspath
kwargs["fspath"] = path

if hasattr(super(), "from_parent"):
result = super().from_parent(parent, fspath=fspath, **kwargs)
result = super().from_parent(parent, **kwargs)
else:
result = AsdfSchemaFile(fspath, parent, **kwargs)
result = AsdfSchemaFile(path, parent)

result.skip_examples = skip_examples
result.validate_default = validate_default
Expand Down Expand Up @@ -238,10 +249,11 @@ def runtest(self):
b._array_storage = "streamed"

try:
with pytest.warns(None) as w:
ff._open_impl(ff, buff, mode='rw')
# Do not tolerate any warnings that occur during schema validation
assert len(w) == 0, helpers.display_warnings(w)
with warnings.catch_warnings():
warnings.simplefilter("error")

ff._open_impl(ff, buff, mode='rw')
except Exception:
print("From file:", self.filename)
raise
Expand Down