From a4db95df98f3648deeba3252d1e32d1131633804 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 31 Aug 2018 23:47:35 +0200 Subject: [PATCH] Use pytest.warns instead of home-baked warnings capture. --- lib/matplotlib/tests/test_legend.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 4f92f044fd6b..f3b7f5758d97 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -282,12 +282,12 @@ def test_warn_args_kwargs(self): th = np.linspace(0, 2*np.pi, 1024) lns, = ax.plot(th, np.sin(th), label='sin', lw=5) lnc, = ax.plot(th, np.cos(th), label='cos', lw=5) - with mock.patch('warnings.warn') as warn: + with pytest.warns(UserWarning) as record: ax.legend((lnc, lns), labels=('a', 'b')) - - warn.assert_called_with("You have mixed positional and keyword " - "arguments, some input may be " - "discarded.") + assert len(record) == 1 + assert str(record[0].message) == ( + "You have mixed positional and keyword arguments, some input may " + "be discarded.") def test_parasite(self): from mpl_toolkits.axes_grid1 import host_subplot @@ -356,11 +356,12 @@ def test_warn_args_kwargs(self): fig, axs = plt.subplots(1, 2) lines = axs[0].plot(range(10)) lines2 = axs[1].plot(np.arange(10) * 2.) - with mock.patch('warnings.warn') as warn: + with pytest.warns(UserWarning) as record: fig.legend((lines, lines2), labels=('a', 'b')) - warn.assert_called_with("You have mixed positional and keyword " - "arguments, some input may be " - "discarded.") + assert len(record) == 1 + assert str(record[0].message) == ( + "You have mixed positional and keyword arguments, some input may " + "be discarded.") @image_comparison(baseline_images=['legend_stackplot'], extensions=['png'])