move _setupstate into session

This commit is contained in:
Benjamin Peterson 2011-05-26 17:08:56 -05:00
parent 89d6defd68
commit dd199d255c
3 changed files with 16 additions and 18 deletions

View File

@ -378,7 +378,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.Collector):
# test generators are seen as collectors but they also # test generators are seen as collectors but they also
# invoke setup/teardown on popular request # invoke setup/teardown on popular request
# (induced by the common "test_*" naming shared with normal tests) # (induced by the common "test_*" naming shared with normal tests)
self.config._setupstate.prepare(self) self.session._setupstate.prepare(self)
# see FunctionMixin.setup and test_setupstate_is_preserved_134 # see FunctionMixin.setup and test_setupstate_is_preserved_134
self._preservedparent = self.parent.obj self._preservedparent = self.parent.obj
l = [] l = []
@ -730,7 +730,7 @@ class FuncargRequest:
def _addfinalizer(self, finalizer, scope): def _addfinalizer(self, finalizer, scope):
colitem = self._getscopeitem(scope) colitem = self._getscopeitem(scope)
self.config._setupstate.addfinalizer( self._pyfuncitem.session._setupstate.addfinalizer(
finalizer=finalizer, colitem=colitem) finalizer=finalizer, colitem=colitem)
def __repr__(self): def __repr__(self):

View File

@ -14,17 +14,15 @@ def pytest_namespace():
# #
# pytest plugin hooks # pytest plugin hooks
# XXX move to pytest_sessionstart and fix py.test owns tests def pytest_sessionstart(session):
def pytest_configure(config): session._setupstate = SetupState()
config._setupstate = SetupState()
def pytest_sessionfinish(session, exitstatus): def pytest_sessionfinish(session, exitstatus):
if hasattr(session.config, '_setupstate'): hook = session.config.hook
hook = session.config.hook rep = hook.pytest__teardown_final(session=session)
rep = hook.pytest__teardown_final(session=session) if rep:
if rep: hook.pytest__teardown_final_logerror(session=session, report=rep)
hook.pytest__teardown_final_logerror(session=session, report=rep) session.exitstatus = 1
session.exitstatus = 1
class NodeInfo: class NodeInfo:
def __init__(self, location): def __init__(self, location):
@ -46,16 +44,16 @@ def runtestprotocol(item, log=True):
return reports return reports
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
item.config._setupstate.prepare(item) item.session._setupstate.prepare(item)
def pytest_runtest_call(item): def pytest_runtest_call(item):
item.runtest() item.runtest()
def pytest_runtest_teardown(item): def pytest_runtest_teardown(item):
item.config._setupstate.teardown_exact(item) item.session._setupstate.teardown_exact(item)
def pytest__teardown_final(session): def pytest__teardown_final(session):
call = CallInfo(session.config._setupstate.teardown_all, when="teardown") call = CallInfo(session._setupstate.teardown_all, when="teardown")
if call.excinfo: if call.excinfo:
ntraceback = call.excinfo.traceback .cut(excludepath=py._pydir) ntraceback = call.excinfo.traceback .cut(excludepath=py._pydir)
call.excinfo.traceback = ntraceback.filter() call.excinfo.traceback = ntraceback.filter()

View File

@ -705,11 +705,11 @@ class TestRequest:
def test_func(something): pass def test_func(something): pass
""") """)
req = funcargs.FuncargRequest(item) req = funcargs.FuncargRequest(item)
req.config._setupstate.prepare(item) # XXX req._pyfuncitem.session._setupstate.prepare(item) # XXX
req._fillfuncargs() req._fillfuncargs()
# successively check finalization calls # successively check finalization calls
teardownlist = item.getparent(pytest.Module).obj.teardownlist teardownlist = item.getparent(pytest.Module).obj.teardownlist
ss = item.config._setupstate ss = item.session._setupstate
assert not teardownlist assert not teardownlist
ss.teardown_exact(item) ss.teardown_exact(item)
print(ss.stack) print(ss.stack)
@ -834,11 +834,11 @@ class TestRequestCachedSetup:
ret1 = req1.cached_setup(setup, teardown, scope="function") ret1 = req1.cached_setup(setup, teardown, scope="function")
assert l == ['setup'] assert l == ['setup']
# artificial call of finalizer # artificial call of finalizer
req1.config._setupstate._callfinalizers(item1) req1._pyfuncitem.session._setupstate._callfinalizers(item1)
assert l == ["setup", "teardown"] assert l == ["setup", "teardown"]
ret2 = req1.cached_setup(setup, teardown, scope="function") ret2 = req1.cached_setup(setup, teardown, scope="function")
assert l == ["setup", "teardown", "setup"] assert l == ["setup", "teardown", "setup"]
req1.config._setupstate._callfinalizers(item1) req1._pyfuncitem.session._setupstate._callfinalizers(item1)
assert l == ["setup", "teardown", "setup", "teardown"] assert l == ["setup", "teardown", "setup", "teardown"]
def test_request_cached_setup_two_args(self, testdir): def test_request_cached_setup_two_args(self, testdir):