From bdec2c8f9e1b39914b5e9fbc6d73adc29cf88f3a Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 22 Jun 2017 08:45:10 +0200 Subject: [PATCH] move marker transfer to _pytest.mark --- _pytest/mark.py | 29 +++++++++++++++++++++++++++++ _pytest/python.py | 31 +------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/_pytest/mark.py b/_pytest/mark.py index 8b40a4f6e..928690d07 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -389,3 +389,32 @@ class MarkInfo(object): MARK_GEN = MarkGenerator() + + +def _marked(func, mark): + """ Returns True if :func: is already marked with :mark:, False otherwise. + This can happen if marker is applied to class and the test file is + invoked more than once. + """ + try: + func_mark = getattr(func, mark.name) + except AttributeError: + return False + return mark.args == func_mark.args and mark.kwargs == func_mark.kwargs + + +def transfer_markers(funcobj, cls, mod): + # XXX this should rather be code in the mark plugin or the mark + # plugin should merge with the python plugin. + for holder in (cls, mod): + try: + pytestmark = holder.pytestmark + except AttributeError: + continue + if isinstance(pytestmark, list): + for mark in pytestmark: + if not _marked(funcobj, mark): + mark(funcobj) + else: + if not _marked(funcobj, pytestmark): + pytestmark(funcobj) diff --git a/_pytest/python.py b/_pytest/python.py index 1a313a59e..c5af9106a 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -23,7 +23,7 @@ from _pytest.compat import ( safe_str, getlocation, enum, ) from _pytest.runner import fail - +from _pytest.mark import transfer_markers cutdir1 = py.path.local(pluggy.__file__.rstrip("oc")) cutdir2 = py.path.local(_pytest.__file__).dirpath() cutdir3 = py.path.local(py.__file__).dirpath() @@ -361,35 +361,6 @@ class PyCollector(PyobjMixin, main.Collector): ) -def _marked(func, mark): - """ Returns True if :func: is already marked with :mark:, False otherwise. - This can happen if marker is applied to class and the test file is - invoked more than once. - """ - try: - func_mark = getattr(func, mark.name) - except AttributeError: - return False - return mark.args == func_mark.args and mark.kwargs == func_mark.kwargs - - -def transfer_markers(funcobj, cls, mod): - # XXX this should rather be code in the mark plugin or the mark - # plugin should merge with the python plugin. - for holder in (cls, mod): - try: - pytestmark = holder.pytestmark - except AttributeError: - continue - if isinstance(pytestmark, list): - for mark in pytestmark: - if not _marked(funcobj, mark): - mark(funcobj) - else: - if not _marked(funcobj, pytestmark): - pytestmark(funcobj) - - class Module(main.File, PyCollector): """ Collector for test classes and functions. """