Skip to content

Commit 68c2df0

Browse files
authored
Merge pull request #72 from jmargeta/pytest_test_function_marking_fix
Fix warnings from updated pytest 3.6 marker API
2 parents 574299c + b838e86 commit 68c2df0

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)