8000 Merge pull request #11992 from anntzer/pytestwarns · matplotlib/matplotlib@b6a3400 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6a3400

Browse files
authored
Merge pull request #11992 from anntzer/pytestwarns
Use pytest.warns instead of home-baked warnings capture.
2 parents a3dc2e1 + a4db95d commit b6a3400

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/matplotlib/tests/test_legend.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ def test_warn_args_kwargs(self):
282282
th = np.linspace(0, 2*np.pi, 1024)
283283
lns, = ax.plot(th, np.sin(th), label='sin', lw=5)
284284
lnc, = ax.plot(th, np.cos(th), label='cos', lw=5)
285-
with mock.patch('warnings.warn') as warn:
285+
with pytest.warns(UserWarning) as record:
286286
ax.legend((lnc, lns), labels=('a', 'b'))
287-
288-
warn.assert_called_with("You have mixed positional and keyword "
289-
"arguments, some input may be "
290-
"discarded.")
287+
assert len(record) == 1
288+
assert str(record[0].message) == (
289+
"You have mixed positional and keyword arguments, some input may "
290+
"be discarded.")
291291

292292
def test_parasite(self):
293293
from mpl_toolkits.axes_grid1 import host_subplot
@@ -356,11 +356,12 @@ def test_warn_args_kwargs(self):
356356
fig, axs = plt.subplots(1, 2)
357357
lines = axs[0].plot(range(10))
358358
lines2 = axs[1].plot(np.arange(10) * 2.)
359-
with mock.patch('warnings.warn') as warn:
359+
with pytest.warns(UserWarning) as record:
360360
fig.legend((lines, lines2), labels=('a', 'b'))
361-
warn.assert_called_with("You have mixed positional and keyword "
362-
"arguments, some input may be "
363-
"discarded.")
361+
assert len(record) == 1
362+
assert str(record[0].message) == (
363+
"You have mixed positional and keyword arguments, some input may "
364+
"be discarded.")
364365

365366

366367
@image_comparison(baseline_images=['legend_stackplot'], extensions=['png'])

0 commit comments

Comments
 (0)
0