[svn r62611] yay, the global setupstate died. I guess what kept me from doing that

was all kinds of tests breaking.  but they are cleaned up now.
so there was no problem. nice.

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-05 22:10:18 +01:00
parent 62b36a91a0
commit 65b75cead6
6 changed files with 47 additions and 57 deletions

View File

@ -27,35 +27,6 @@ def configproperty(name):
return self._config.getvalue(name, self.fspath) return self._config.getvalue(name, self.fspath)
return property(fget) return property(fget)
class SetupState(object):
""" shared state for setting up/tearing down test items or collectors. """
def __init__(self):
self.stack = []
def teardown_all(self):
while self.stack:
col = self.stack.pop()
col.teardown()
def teardown_exact(self, item):
if self.stack and self.stack[-1] == item:
col = self.stack.pop()
col.teardown()
def prepare(self, colitem):
""" setup objects along the collector chain to the test-method
Teardown any unneccessary previously setup objects."""
needed_collectors = colitem.listchain()
while self.stack:
if self.stack == needed_collectors[:len(self.stack)]:
break
col = self.stack.pop()
col.teardown()
for col in needed_collectors[len(self.stack):]:
col.setup()
self.stack.append(col)
class ReprMetaInfo(object): class ReprMetaInfo(object):
def __init__(self, fspath=None, lineno=None, modpath=None): def __init__(self, fspath=None, lineno=None, modpath=None):
self.fspath = fspath self.fspath = fspath
@ -95,10 +66,6 @@ class Node(object):
stdout/stderr capturing and execution of test items stdout/stderr capturing and execution of test items
""" """
ReprMetaInfo = ReprMetaInfo ReprMetaInfo = ReprMetaInfo
# XXX we keep global SetupState here because
# pycollect's Generators participate
# in setup/teardown procedures during collect.
_setupstate = SetupState()
def __init__(self, name, parent=None, config=None): def __init__(self, name, parent=None, config=None):
self.name = name self.name = name
self.parent = parent self.parent = parent

View File

@ -40,6 +40,7 @@ class Config(object):
self.bus = pytestplugins.pyplugins self.bus = pytestplugins.pyplugins
self.pytestplugins = pytestplugins self.pytestplugins = pytestplugins
self._conftest = Conftest(onimport=self.pytestplugins.consider_conftest) self._conftest = Conftest(onimport=self.pytestplugins.consider_conftest)
self._setupstate = SetupState()
def _processopt(self, opt): def _processopt(self, opt):
if hasattr(opt, 'default') and opt.dest: if hasattr(opt, 'default') and opt.dest:
@ -210,11 +211,6 @@ class Config(object):
raise ValueError("unknown io capturing: " + iocapture) raise ValueError("unknown io capturing: " + iocapture)
# this is the one per-process instance of py.test configuration
config_per_process = Config(
pytestplugins=py.test._PytestPlugins(py._com.pyplugins)
)
# #
# helpers # helpers
# #
@ -240,3 +236,38 @@ def gettopdir(args):
return p return p
else: else:
return pkgdir.dirpath() return pkgdir.dirpath()
class SetupState(object):
""" shared state for setting up/tearing down test items or collectors. """
def __init__(self):
self.stack = []
def teardown_all(self):
while self.stack:
col = self.stack.pop()
col.teardown()
def teardown_exact(self, item):
if self.stack and self.stack[-1] == item:
col = self.stack.pop()
col.teardown()
def prepare(self, colitem):
""" setup objects along the collector chain to the test-method
Teardown any unneccessary previously setup objects."""
needed_collectors = colitem.listchain()
while self.stack:
if self.stack == needed_collectors[:len(self.stack)]:
break
col = self.stack.pop()
col.teardown()
for col in needed_collectors[len(self.stack):]:
col.setup()
self.stack.append(col)
# this is the one per-process instance of py.test configuration
config_per_process = Config(
pytestplugins=py.test._PytestPlugins(py._com.pyplugins)
)

View File

@ -5,7 +5,6 @@ pytes plugin for easing testing of pytest runs themselves.
import py import py
from py.__.test import event from py.__.test import event
from py.__.test.config import Config as pytestConfig from py.__.test.config import Config as pytestConfig
from py.__.test.collect import Node, SetupState
class PytesterPlugin: class PytesterPlugin:
def pytest_pyfuncarg_linecomp(self, pyfuncitem): def pytest_pyfuncarg_linecomp(self, pyfuncitem):
@ -134,20 +133,13 @@ class TmpTestdir:
return self.inline_run(*l) return self.inline_run(*l)
def inline_run(self, *args): def inline_run(self, *args):
# for the inlined test session we should not modify config = self.parseconfig(*args)
# our caller's test state config.pytestplugins.do_configure(config)
oldstate = Node._setupstate session = config.initsession()
Node._setupstate = SetupState() sorter = EventRecorder(config.bus)
try: session.main()
config = self.parseconfig(*args) config.pytestplugins.do_unconfigure(config)
config.pytestplugins.do_configure(config) return sorter
session = config.initsession()
sorter = EventRecorder(config.bus)
session.main()
config.pytestplugins.do_unconfigure(config)
return sorter
finally:
Node._setupstate = oldstate
def config_preparse(self): def config_preparse(self):
config = self.Config() config = self.Config()

View File

@ -289,7 +289,7 @@ class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector):
# test generators are collectors yet participate in # test generators are collectors yet participate in
# the test-item setup and teardown protocol. # the test-item setup and teardown protocol.
# otherwise we could avoid global setupstate # otherwise we could avoid global setupstate
self._setupstate.prepare(self) self._config._setupstate.prepare(self)
l = [] l = []
for i, x in py.builtin.enumerate(self.obj()): for i, x in py.builtin.enumerate(self.obj()):
name, call, args = self.getcallargs(x) name, call, args = self.getcallargs(x)

View File

@ -50,9 +50,9 @@ class RobustRun(object):
class ItemRunner(RobustRun): class ItemRunner(RobustRun):
def setup(self): def setup(self):
self.colitem._setupstate.prepare(self.colitem) self.colitem._config._setupstate.prepare(self.colitem)
def teardown(self): def teardown(self):
self.colitem._setupstate.teardown_exact(self.colitem) self.colitem._config._setupstate.teardown_exact(self.colitem)
def execute(self): def execute(self):
#self.colitem.config.pytestplugins.pre_execute(self.colitem) #self.colitem.config.pytestplugins.pre_execute(self.colitem)
self.colitem.runtest() self.colitem.runtest()

View File

@ -124,7 +124,7 @@ class Session(object):
if not self.config.option.collectonly: if not self.config.option.collectonly:
self.runtest(item) self.runtest(item)
py.test.collect.Item._setupstate.teardown_all() self.config._setupstate.teardown_all()
except KeyboardInterrupt: except KeyboardInterrupt:
captured_excinfo = py.code.ExceptionInfo() captured_excinfo = py.code.ExceptionInfo()
exitstatus = outcome.EXIT_INTERRUPTED exitstatus = outcome.EXIT_INTERRUPTED