[svn r62211] merge 60797:HEAD of pytestplugin branch:

this merge contains:

* a new plugin architecture
* a pluginized pytest core
* many pytest related refactorings
* refactorings/streamlining of pytest's own tests

--HG--
branch : trunk
This commit is contained in:
hpk
2009-02-27 11:18:27 +01:00
parent 1c85d7fe9a
commit c17a09adaf
117 changed files with 6079 additions and 4370 deletions

View File

@@ -7,14 +7,10 @@
import py
from py.__.test import event, outcome
from py.__.test.event import EventBus
import py.__.test.custompdb
from py.__.test.resultlog import ResultLog
# used for genitems()
from py.__.test.outcome import Exit
Item = (py.test.collect.Item, py.test.collect.Item)
Collector = (py.test.collect.Collector, py.test.collect.Collector)
# imports used for genitems()
Item = py.test.collect.Item
Collector = py.test.collect.Collector
from runner import basic_collect_report
from py.__.test.dsession.hostmanage import makehostup
@@ -25,20 +21,10 @@ class Session(object):
"""
def __init__(self, config):
self.config = config
self.bus = EventBus()
self.bus = config.bus # shortcut
self.bus.register(self)
self._testsfailed = False
self._nomatch = False
eventlog = self.config.option.eventlog
if eventlog:
self.eventlog = py.path.local(eventlog)
f = self.eventlog.open("w")
def eventwrite(ev):
print >>f, ev
f.flush()
self.bus.subscribe(eventwrite)
resultlog = self.config.option.resultlog
if resultlog:
f = open(resultlog, 'w', 1) # line buffered
self.resultlog = ResultLog(self.bus, f)
def fixoptions(self):
""" check, fix and determine conflicting options. """
@@ -56,19 +42,24 @@ class Session(object):
""" yield Items from iterating over the given colitems. """
while colitems:
next = colitems.pop(0)
if isinstance(next, (tuple, list)):
colitems[:] = list(next) + colitems
continue
assert self.bus is next._config.bus
notify = self.bus.notify
if isinstance(next, Item):
remaining = self.filteritems([next])
if remaining:
self.bus.notify(event.ItemStart(next))
notify("itemstart", event.ItemStart(next))
yield next
else:
assert isinstance(next, Collector)
self.bus.notify(event.CollectionStart(next))
notify("collectionstart", event.CollectionStart(next))
ev = basic_collect_report(next)
if ev.passed:
for x in self.genitems(ev.result, keywordexpr):
yield x
self.bus.notify(ev)
notify("collectionreport", ev)
def filteritems(self, colitems):
""" return items to process (some may be deselected)"""
@@ -86,7 +77,7 @@ class Session(object):
continue
remaining.append(colitem)
if deselected:
self.bus.notify(event.Deselected(deselected, ))
self.bus.notify("deselected", event.Deselected(deselected, ))
if self.config.option.keyword.endswith(":"):
self._nomatch = True
return remaining
@@ -98,23 +89,19 @@ class Session(object):
def sessionstarts(self):
""" setup any neccessary resources ahead of the test run. """
self.bus.notify(event.TestrunStart())
self._failurelist = []
self.bus.subscribe(self._processfailures)
def _processfailures(self, ev):
if isinstance(ev, event.BaseReport) and ev.failed:
self._failurelist.append(ev)
if self.config.option.exitfirst:
self.shouldstop = True
self.bus.notify("testrunstart", event.TestrunStart())
def pyevent_itemtestreport(self, rep):
if rep.failed:
self._testsfailed = True
if self.config.option.exitfirst:
self.shouldstop = True
pyevent_collectionreport = pyevent_itemtestreport
def sessionfinishes(self, exitstatus=0, excinfo=None):
""" teardown any resources after a test run. """
self.bus.notify(event.TestrunFinish(exitstatus=exitstatus,
excinfo=excinfo))
self.bus.unsubscribe(self._processfailures)
#self.reporter.deactivate()
return self._failurelist
self.bus.notify("testrunfinish",
event.TestrunFinish(exitstatus=exitstatus, excinfo=excinfo))
def getinitialitems(self, colitems):
if colitems is None:
@@ -127,7 +114,7 @@ class Session(object):
colitems = self.getinitialitems(colitems)
self.shouldstop = False
self.sessionstarts()
self.bus.notify(makehostup())
self.bus.notify("hostup", makehostup())
exitstatus = outcome.EXIT_OK
captured_excinfo = None
try:
@@ -136,24 +123,26 @@ class Session(object):
break
if not self.config.option.collectonly:
self.runtest(item)
py.test.collect.Item._setupstate.teardown_all()
except KeyboardInterrupt:
captured_excinfo = py.code.ExceptionInfo()
exitstatus = outcome.EXIT_INTERRUPTED
except:
self.bus.notify(event.InternalException())
captured_excinfo = py.code.ExceptionInfo()
self.bus.notify("internalerror", event.InternalException(captured_excinfo))
exitstatus = outcome.EXIT_INTERNALERROR
if self._failurelist and exitstatus == 0:
if exitstatus == 0 and self._testsfailed:
exitstatus = outcome.EXIT_TESTSFAILED
self.sessionfinishes(exitstatus=exitstatus, excinfo=captured_excinfo)
return exitstatus
def runpdb(self, excinfo):
py.__.test.custompdb.post_mortem(excinfo._excinfo[2])
from py.__.test.custompdb import post_mortem
post_mortem(excinfo._excinfo[2])
def runtest(self, item):
runner = item._getrunner()
pdb = self.config.option.usepdb and self.runpdb or None
testrep = runner(item, pdb=pdb)
self.bus.notify(testrep)
self.bus.notify("itemtestreport", testrep)