Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7726a3

Browse files
committed
Make _warn_external correctly report warnings arising from tests.
Before the PR: ``` $ pytest lib/matplotlib/tests/test_cbook.py::test_is_hashable <elided> lib/matplotlib/tests/test_cbook.py::test_is_hashable .../site-packages/_pytest/python.py:166: MatplotlibDeprecationWarning: The is_hashable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use isinstance(..., collections.abc.Hashable) instead. testfunction(**testargs) -- Docs: https://docs.pytest.org/en/latest/warnings.html ``` After ``` $ pytest lib/matplotlib/tests/test_cbook.py::test_is_hashable <elided> lib/matplotlib/tests/test_cbook.py::test_is_hashable .../lib/matplotlib/tests/test_cbook.py:22: MatplotlibDeprecationWarning: The is_hashable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use isinstance(..., collections.abc.Hashable) instead. assert cbook.is_hashable(s) lib/matplotlib/tests/test_cbook.py::test_is_hashable .../lib/matplotlib/tests/test_cbook.py:25: MatplotlibDeprecationWarning: The is_hashable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use isinstance(..., collections.abc.Hashable) instead. assert not cbook.is_hashable(lst) ```
1 parent 83cb3ef commit d7726a3

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/matplotlib/cbook/__init__.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)