From a86118d77b840141d36ac5adb05ccdf85b0a6003 Mon Sep 17 00:00:00 2001 From: arigo Date: Tue, 27 Mar 2007 15:28:18 +0200 Subject: [PATCH] [svn r41480] Move the FunctionMixin to collect.py, as an attempt to avoid circular imports. --HG-- branch : trunk --- py/test/collect.py | 33 ++++++++++++++++++++++++++++++++- py/test/item.py | 33 +-------------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/py/test/collect.py b/py/test/collect.py index 0b1f30237..a6d33d0bd 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -442,7 +442,38 @@ class Instance(PyCollectorMixin, Collector): Collector.Function.__get__(self)) # XXX for python 2.2 Function = property(Function) -from py.__.test.item import FunctionMixin # XXX import order issues :-( + +class FunctionMixin(object): + """ mixin for the code common to Function and Generator. + """ + def _getpathlineno(self): + code = py.code.Code(self.obj) + return code.path, code.firstlineno + + def _getsortvalue(self): + return self._getpathlineno() + + def setup(self): + """ perform setup for this test function. """ + if getattr(self.obj, 'im_self', None): + name = 'setup_method' + else: + name = 'setup_function' + obj = self.parent.obj + meth = getattr(obj, name, None) + if meth is not None: + return meth(self.obj) + + def teardown(self): + """ perform teardown for this test function. """ + if getattr(self.obj, 'im_self', None): + name = 'teardown_method' + else: + name = 'teardown_function' + obj = self.parent.obj + meth = getattr(obj, name, None) + if meth is not None: + return meth(self.obj) class Generator(FunctionMixin, PyCollectorMixin, Collector): def run(self): diff --git a/py/test/item.py b/py/test/item.py index ac4fab9d6..5a77b583d 100644 --- a/py/test/item.py +++ b/py/test/item.py @@ -2,6 +2,7 @@ import py from inspect import isclass, ismodule from py.__.test.outcome import Skipped, Failed, Passed +from py.__.test.collect import FunctionMixin _dummy = object() @@ -37,38 +38,6 @@ class Item(py.test.collect.Collector): def finishcapture(self): self._config._finishcapture(self) -class FunctionMixin(object): - """ mixin for the code common to Function and Generator. - """ - def _getpathlineno(self): - code = py.code.Code(self.obj) - return code.path, code.firstlineno - - def _getsortvalue(self): - return self._getpathlineno() - - def setup(self): - """ perform setup for this test function. """ - if getattr(self.obj, 'im_self', None): - name = 'setup_method' - else: - name = 'setup_function' - obj = self.parent.obj - meth = getattr(obj, name, None) - if meth is not None: - return meth(self.obj) - - def teardown(self): - """ perform teardown for this test function. """ - if getattr(self.obj, 'im_self', None): - name = 'teardown_method' - else: - name = 'teardown_function' - obj = self.parent.obj - meth = getattr(obj, name, None) - if meth is not None: - return meth(self.obj) - class Function(FunctionMixin, Item): """ a Function Item is responsible for setting up and executing a Python callable test object.