[svn r62610] finally fixed a bug related to the global SetupState

for test functions.  streamlined  testdir.inline_run
functions.  well killed most of them.

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-05 22:01:08 +01:00
parent 7688f88c4f
commit 62b36a91a0
4 changed files with 40 additions and 44 deletions

View File

@ -90,11 +90,8 @@ class TestAsyncFunctional:
# assert py.__file__ != '%s'
""" % (tmpdir.join(subdir), py.__file__)))
destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath())
config = py.test.config._reparse([tmpdir.join(subdir)])
assert config.topdir == tmpdir
assert not tmpdir.join("__init__.py").check()
dist = DSession(config)
sorter = testdir.inline_runsession(dist)
sorter = testdir.inline_run(tmpdir.join(subdir))
testevents = sorter.getnamed('itemtestreport')
assert len([x for x in testevents if x.passed]) == 2
assert len([x for x in testevents if x.failed]) == 3

View File

@ -107,7 +107,7 @@ class TestDoctests:
>>> x == 1
False
""")
events = testdir.inline_run_with_plugins(p)
events = testdir.inline_run(p)
ev, = events.getnamed("itemtestreport")
assert ev.failed
@ -143,7 +143,7 @@ class TestDoctests:
'''
""")
events = testdir.inline_run_with_plugins(p, "--doctest-modules")
events = testdir.inline_run(p, "--doctest-modules")
ev, = events.getnamed("itemtestreport")
assert ev.failed

View File

@ -8,15 +8,16 @@ class url:
xmlrpc = base + "/xmlrpc/"
show = base + "/show/"
class PocooPlugin(object):
class PocooPlugin:
""" report URLs from sending test failures to the pocoo paste service. """
def pytest_addoption(self, parser):
parser.addoption('--pocoo-sendfailures',
parser.addoption('-P', '--pocoo-sendfailures',
action='store_true', dest="pocoo_sendfailures",
help="send failures to %s" %(url.base,))
def getproxy(self):
assert 0
return py.std.xmlrpclib.ServerProxy(url.xmlrpc).pastes
def pytest_terminal_summary(self, terminalreporter):
@ -25,6 +26,8 @@ class PocooPlugin(object):
if 'failed' in tr.stats and tr.config.option.tbstyle != "no":
terminalreporter.write_sep("=", "Sending failures to %s" %(url.base,))
terminalreporter.write_line("xmlrpcurl: %s" %(url.xmlrpc,))
print self.__class__.getproxy
print self.__class__, id(self.__class__)
serverproxy = self.getproxy()
for ev in terminalreporter.stats.get('failed'):
tw = py.io.TerminalWriter(stringio=True)
@ -33,17 +36,22 @@ class PocooPlugin(object):
# XXX add failure summary
assert len(s)
terminalreporter.write_line("newpaste() ...")
id = serverproxy.newPaste("python", s)
terminalreporter.write_line("%s%s\n" % (url.show, id))
proxyid = serverproxy.newPaste("python", s)
terminalreporter.write_line("%s%s\n" % (url.show, proxyid))
break
def test_apicheck(plugintester):
plugintester.apicheck(PocooPlugin)
pytest_plugins = 'pytest_monkeypatch',
def test_toproxy(testdir, monkeypatch):
testdir.makepyfile(conftest="pytest_plugins='pytest_pocoo',")
l = []
class MockProxy:
def newPaste(self, language, code):
l.append((language, code))
monkeypatch.setattr(PocooPlugin, 'getproxy', MockProxy)
testdir.plugins.insert(0, PocooPlugin())
testdir.chdir()
testpath = testdir.makepyfile("""
import py
def test_pass():
@ -53,10 +61,10 @@ def test_toproxy(testdir, monkeypatch):
def test_skip():
py.test.skip("")
""")
l = []
class MockProxy:
def newPaste(self, language, code):
l.append((language, code))
monkeypatch.setattr(PocooPlugin, 'getproxy', MockProxy)
result = testdir.inline_run(testpath, "--pocoo-sendfailures")
evrec = testdir.inline_run(testpath, "-P")
assert len(l) == 1
assert l[0][0] == "python"
s = l[0][1]
assert s.find("def test_fail") != -1
assert evrec.countoutcomes() == [1,1,1]

View File

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