Skip to content

Commit bdec2c8

Browse files
move marker transfer to _pytest.mark
1 parent 9bd8907 commit bdec2c8

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

_pytest/mark.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,32 @@ def __iter__(self):
389389

390390

391391
MARK_GEN = MarkGenerator()
392+
393+
394+
def _marked(func, mark):
395+
""" Returns True if :func: is already marked with :mark:, False otherwise.
396+
This can happen if marker is applied to class and the test file is
397+
invoked more than once.
398+
"""
399+
try:
400+
func_mark = getattr(func, mark.name)
401+
except AttributeError:
402+
return False
403+
return mark.args == func_mark.args and mark.kwargs == func_mark.kwargs
404+
405+
406+
def transfer_markers(funcobj, cls, mod):
407+
# XXX this should rather be code in the mark plugin or the mark
408+
# plugin should merge with the python plugin.
409+
for holder in (cls, mod):
410+
try:
411+
pytestmark = holder.pytestmark
412+
except AttributeError:
413+
continue
414+
if isinstance(pytestmark, list):
415+
for mark in pytestmark:
416+
if not _marked(funcobj, mark):
417+
mark(funcobj)
418+
else:
419+
if not _marked(funcobj, pytestmark):
420+
pytestmark(funcobj)

_pytest/python.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
safe_str, getlocation, enum,
2424
)
2525
from _pytest.runner import fail
26-
26+
from _pytest.mark import transfer_markers
2727
cutdir1 = py.path.local(pluggy.__file__.rstrip("oc"))
2828
cutdir2 = py.path.local(_pytest.__file__).dirpath()
2929
cutdir3 = py.path.local(py.__file__).dirpath()
@@ -361,35 +361,6 @@ def _genfunctions(self, name, funcobj):
361361
)
362362

363363

364-
def _marked(func, mark):
365-
""" Returns True if :func: is already marked with :mark:, False otherwise.
366-
This can happen if marker is applied to class and the test file is
367-
invoked more than once.
368-
"""
369-
try:
370-
func_mark = getattr(func, mark.name)
371-
except AttributeError:
372-
return False
373-
return mark.args == func_mark.args and mark.kwargs == func_mark.kwargs
374-
375-
376-
def transfer_markers(funcobj, cls, mod):
377-
# XXX this should rather be code in the mark plugin or the mark
378-
# plugin should merge with the python plugin.
379-
for holder in (cls, mod):
380-
try:
381-
pytestmark = holder.pytestmark
382-
except AttributeError:
383-
continue
384-
if isinstance(pytestmark, list):
385-
for mark in pytestmark:
386-
if not _marked(funcobj, mark):
387-
mark(funcobj)
388-
else:
389-
if not _marked(funcobj, pytestmark):
390-
pytestmark(funcobj)
391-
392-
393364
class Module(main.File, PyCollector):
394365
""" Collector for test classes and functions. """
395366

0 commit comments

Comments
 (0)