Skip to content

Commit

Permalink
Fixed issues from removal of pytest.warns(None) in pytest version 8
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed May 4, 2024
1 parent cd30117 commit 2ba63bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Released: not yet
macos-latest back to macos-12 because macos-latest got upgraded from macOS 12
to macOS 14 which no longer supports these Python versions.

* Test: Fixed issues resulting from removal of support for pytest.warns(None)
in pytest version 8.

**Enhancements:**

* Improvements for safety check tool: Made passing the safety check mandatory;
Expand Down
5 changes: 3 additions & 2 deletions tests/utils/simplified_test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import

import functools
import warnings
from collections import namedtuple
from inspect import Signature, Parameter # type: ignore
import pytest
Expand Down Expand Up @@ -148,7 +149,7 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition):
ret = None # Debugging hint
assert len(rec_warnings) >= 1
else:
with pytest.warns(None) as rec_warnings:
with warnings.catch_warnings(record=True) as rec_warnings:
if exp_exc_types:
with pytest.raises(exp_exc_types):
if condition == 'pdb':
Expand All @@ -170,7 +171,7 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition):
# Verify that no warnings have occurred
if exp_warn_types is None and rec_warnings:
lines = []
for w in rec_warnings.list:
for w in rec_warnings:
tup = (w.filename, w.lineno, w.category.__name__,
str(w.message))
line = "{t[0]}:{t[1]}: {t[2]}: {t[3]}".format(t=tup)
Expand Down

0 comments on commit 2ba63bf

Please sign in to comment.