@@ -197,25 +197,40 @@ def pytest_configure():
197
197
198
198
# Platform Markers
199
199
200
- PLAT = sys .platform .lower ()
201
- IMPL = platform .python_implementation ().lower ()
202
- PYMAJ = str (sys .version_info .major )
203
- PYNAME = "py" + PYMAJ
204
-
205
- CURRENT = {PLAT , IMPL , PYNAME , IMPL + PYMAJ }
206
- START = {"xfail" , "skip" }
200
+ PLAT = sys .platform .lower () # linux, osx, or win32
201
+ IMPL = platform .python_implementation ().lower () # cpython or pypy
207
202
208
203
209
204
def pytest_collection_modifyitems (items ):
205
+ """
206
+ This will find the markers listed in pytest.ini and add
207
+ skip or xfail as needed. The second part can be a platform
208
+ marker (linux, osx, or win32), or python, cpython, or pypy.
209
+
210
+ You can add also add Python version numbers - either 2 or 3.
211
+
212
+ Keyword arguments are passed on.
213
+
214
+ # Will skip on Python 2
215
+ pytest.mark.skip_python(2)
216
+
217
+ # Will xfail on pypy as long as TypeError is raised
218
+ pytest.mark.xfail_pypy(reason="Not supported", raises=TypeError)
219
+ """
210
220
for item in items :
211
221
for mark in tuple (item .iter_markers ()):
222
+ # Check for recognised name
212
223
parts = mark .name .split ("_" )
213
- if len (parts ) == 2 and parts [0 ] in START and parts [ 1 ] in CURRENT :
224
+ if len (parts ) == 2 and parts [0 ] in { "xfail" , "skip" } :
214
225
marker = getattr (pytest .mark , parts [0 ])
215
- reason = "expected to fail on {}" .format (parts [1 ])
216
226
217
- item .add_marker (
218
- marker (** mark .kwargs )
219
- if "reason" in mark .kwargs
220
- else marker (reason = reason , ** mark .kwargs )
221
- )
227
+ if parts [1 ] in {PLAT , IMPL , "python" }:
228
+ # args lets you remove only Py 2 or 3
229
+ if mark .args :
230
+ (ver ,) = mark .args # Only single argument supported
231
+ assert isinstance (ver , int ), "should be a version number"
232
+ if ver == sys .version_info .major :
233
+ item .add_marker (marker (** mark .kwargs ))
234
+ else :
235
+ assert parts [1 ] != "python" , "version required (otherwise use mark.skip)"
236
+ item .add_marker (marker (** mark .kwargs ))
0 commit comments