feat: 10865
This commit is contained in:
parent
aaa9ca7327
commit
62c6f53689
|
@ -0,0 +1 @@
|
||||||
|
Fix a TypeError in a warning arguments call muted by warnings filter.
|
|
@ -329,3 +329,11 @@ class WarningsChecker(WarningsRecorder):
|
||||||
module=w.__module__,
|
module=w.__module__,
|
||||||
source=w.source,
|
source=w.source,
|
||||||
)
|
)
|
||||||
|
# Check warnings has valid argument type
|
||||||
|
wrn: warnings.WarningMessage
|
||||||
|
for wrn in self:
|
||||||
|
if isinstance(wrn.message, Warning):
|
||||||
|
if not isinstance(wrn.message.args[0], str):
|
||||||
|
raise TypeError(
|
||||||
|
f"Warning message must be str, got {type(wrn.message.args[0])}"
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
from _pytest.pytester import Pytester
|
||||||
|
|
||||||
|
|
||||||
|
class TestWarningAttributes:
|
||||||
|
def test_raise_type_error(self, pytester: Pytester) -> None:
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
def test_example_one():
|
||||||
|
with pytest.warns(UserWarning):
|
||||||
|
warnings.warn(1)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest()
|
||||||
|
result.stdout.fnmatch_lines(["*1 failed*"])
|
Loading…
Reference in New Issue