feat: 10865

This commit is contained in:
Volodymyr Kochetkov 2024-01-12 08:57:36 +02:00
parent aaa9ca7327
commit 62c6f53689
3 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1 @@
Fix a TypeError in a warning arguments call muted by warnings filter.

View File

@ -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])}"
)

View File

@ -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*"])