8000 gh-122191: Fix test_warnings failure if run with -Werror by serhiy-storchaka · Pull Request #122222 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122191: Fix test_warnings failure if run with -Werror #122222

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

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Ensure that get_source() was called.
  • Loading branch information
serhiy-storchaka committed Jul 24, 2024
commit 97640743e21394fb7800a42045e18be9e49ded54
7 changes: 7 additions & 0 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,15 @@ def test_issue31285(self):
# warn_explicit() should neither raise a SystemError nor cause an
# assertion failure, in case the return value of get_source() has a
# bad splitlines() method.
get_source_called = []
def get_module_globals(*, splitlines_ret_val):
class BadSource(str):
def splitlines(self):
return splitlines_ret_val

class BadLoader:
def get_source(self, fullname):
get_source_called.append(splitlines_ret_val)
return BadSource('spam')

loader = BadLoader()
Expand All @@ -908,19 +910,24 @@ def get_source(self, fullname):
with original_warnings.catch_warnings(module=wmod):
wmod.filterwarnings('default', category=UserWarning)

linecache.clearcache()
with support.captured_stderr() as stderr:
wmod.warn_explicit(
'foo', UserWarning, 'bar', 1,
module_globals=get_module_globals(splitlines_ret_val=42))
self.assertIn('UserWarning: foo', stderr.getvalue())
self.assertEqual(get_source_called, [42])

linecache.clearcache()
with support.swap_attr(wmod, '_showwarnmsg', None):
del wmod._showwarnmsg
with support.captured_stderr() as stderr:
wmod.warn_explicit(
'eggs', UserWarning, 'bar', 1,
module_globals=get_module_globals(splitlines_ret_val=[42]))
self.assertIn('UserWarning: eggs', stderr.getvalue())
self.assertEqual(get_source_called, [42, [42]])
linecache.clearcache()

@support.cpython_only
def test_issue31411(self):
Expand Down
Loading
0