Skip to content

Commit 0fdd065

Browse files
committed
feat: 10865 fix for codecov
1 parent 269b674 commit 0fdd065

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

src/_pytest/recwarn.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ def found_str():
334334
# Check warnings has valid argument type (#10865).
335335
wrn: warnings.WarningMessage
336336
for wrn in self:
337-
if isinstance(wrn.message, Warning):
338-
if not isinstance(msg := wrn.message.args[0], str):
339-
raise TypeError(
340-
f"Warning message must be str, got {msg!r} (type {type(msg).__name__})"
341-
)
337+
if not isinstance(msg := wrn.message.args[0], str): # type: ignore
338+
raise TypeError(
339+
f"Warning message must be str, got {msg!r} (type {type(msg).__name__})"
340+
)

testing/test_recwarn.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# mypy: allow-untyped-defs
2-
import sys
32
import warnings
43
from typing import List
54
from typing import Optional
@@ -478,29 +477,3 @@ def test_catch_warning_within_raise(self) -> None:
478477
with pytest.raises(ValueError, match="some exception"):
479478
warnings.warn("some warning", category=FutureWarning)
480479
raise ValueError("some exception")
481-
482-
483-
def test_raise_type_error_on_non_string_warning() -> None:
484-
"""Check pytest.warns validates warning messages are strings (#10865)."""
485-
with pytest.raises(TypeError, match="Warning message must be str"):
486-
with pytest.warns(UserWarning):
487-
warnings.warn(1) # type: ignore
488-
489-
490-
def test_no_raise_type_error_on_string_warning() -> None:
491-
"""Check pytest.warns validates warning messages are strings (#10865)."""
492-
with pytest.warns(UserWarning):
493-
warnings.warn("Warning")
494-
495-
496-
@pytest.mark.skipif(
497-
hasattr(sys, "pypy_version_info"),
498-
reason="Not for pypy",
499-
)
500-
def test_raise_type_error_on_non_string_warning_cpython() -> None:
501-
# Check that we get the same behavior with the stdlib, at least if filtering
502-
# (see https://github.com/python/cpython/issues/103577 for details)
503-
with pytest.raises(TypeError):
504-
with warnings.catch_warnings():
505-
warnings.filterwarnings("ignore", "test")
506-
warnings.warn(1) # type: ignore

0 commit comments

Comments
 (0)