8000 Merge pull request #13795 from anntzer/warnexternal-tests · matplotlib/matplotlib@e652c8b · GitHub
[go: up one dir, main page]

Skip to content

Commit e652c8b

Browse files
authored
Merge pull request #13795 from anntzer/warnexternal-tests
Make _warn_external correctly report warnings arising from tests.
2 parents 366a5d1 + d7726a3 commit e652c8b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/matplotlib/cbook/__init__ 8000 .py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ def _warn_external(message, category=None):
20412041
if frame is None:
20422042
# when called in embedded context may hit frame is None
20432043
break
2044-
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)",
2044+
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))",
20452045
# Work around sphinx-gallery not setting __name__.
20462046
frame.f_globals.get("__name__", "")):
20472047
break

lib/matplotlib/tests/test_cbook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,9 @@ def func(pre, arg, post=None):
560560
func(1, 2)
561561
with pytest.warns(MatplotlibDeprecationWarning):
562562
func(1, 2, 3)
563+
564+
565+
def test_warn_external(recwarn):
566+
cbook._warn_external("oops")
567+
assert len(recwarn) == 1
568+
assert recwarn[0].filename == __file__

0 commit comments

Comments
 (0)
0