Skip to content

Commit b838e86

Browse files
committed
Fix warnings from updated marker API in pytest 3.6
Use of item.get_marker was deprecated. Tests with the matplotlib decorator run but result in warnings such as: tests/test_visualization.py::test_show_checkerboard_overlay /home/_/venvs/python3.6/site-packages/pytest_mpl/plugin.py:175: RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly. Please use node.get_closest_marker(name) or node.iter_markers(name). Docs: https://docs.pytest.org/en/latest/mark.html#updating-code tolerance = compare.kwargs.get('tolerance', 2) This patch uses get_closest_marker instead of the get_marker and fixes the issue. See also: Marker revamp and iteration https://docs.pytest.org/en/latest/mark.html#updating-code
1 parent 574299c commit b838e86

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pytest_mpl/plugin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def close_mpl_figure(fig):
157157
plt.close(fig)
158158

159159

160+
def get_marker(item, marker_name):
161+
if hasattr(item, 'get_closest_marker'):
162+
return item.get_closest_marker(marker_name)
163+
else:
164+
# "item.keywords.get" was deprecated in pytest 3.6
165+
# See https://docs.pytest.org/en/latest/mark.html#updating-code
166+
return item.keywords.get(marker_name)
167+
168+
160169
class ImageComparison(object):
161170

162171
def __init__(self, config, baseline_dir=None, generate_dir=None, results_dir=None):
@@ -169,7 +178,7 @@ def __init__(self, config, baseline_dir=None, generate_dir=None, results_dir=Non
169178

170179
def pytest_runtest_setup(self, item):
171180

172-
compare = item.keywords.get('mpl_image_compare')
181+
compare = get_marker(item, 'mpl_image_compare')
173182

174183
if compare is None:
175184
return
@@ -295,7 +304,7 @@ def __init__(self, config):
295304

296305
def pytest_runtest_setup(self, item):
297306

298-
compare = item.keywords.get('mpl_image_compare')
307+
compare = get_marker(item, 'mpl_image_compare')
299308

300309
if compare is None:
301310
return

0 commit comments

Comments
 (0)