[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' # assert py.__file__ != '%s'
""" % (tmpdir.join(subdir), py.__file__))) """ % (tmpdir.join(subdir), py.__file__)))
destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath()) destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath())
config = py.test.config._reparse([tmpdir.join(subdir)])
assert config.topdir == tmpdir sorter = testdir.inline_run(tmpdir.join(subdir))
assert not tmpdir.join("__init__.py").check()
dist = DSession(config)
sorter = testdir.inline_runsession(dist)
testevents = sorter.getnamed('itemtestreport') testevents = sorter.getnamed('itemtestreport')
assert len([x for x in testevents if x.passed]) == 2 assert len([x for x in testevents if x.passed]) == 2
assert len([x for x in testevents if x.failed]) == 3 assert len([x for x in testevents if x.failed]) == 3

View File

@ -107,7 +107,7 @@ class TestDoctests:
>>> x == 1 >>> x == 1
False False
""") """)
events = testdir.inline_run_with_plugins(p) events = testdir.inline_run(p)
ev, = events.getnamed("itemtestreport") ev, = events.getnamed("itemtestreport")
assert ev.failed 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") ev, = events.getnamed("itemtestreport")
assert ev.failed assert ev.failed

View File

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

View File

@ -5,6 +5,7 @@ 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):
@ -132,15 +133,12 @@ class TmpTestdir:
l = list(cmdlineargs) + [p] l = list(cmdlineargs) + [p]
return self.inline_run(*l) 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): def inline_run(self, *args):
# 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 = self.parseconfig(*args)
config.pytestplugins.do_configure(config) config.pytestplugins.do_configure(config)
session = config.initsession() session = config.initsession()
@ -148,15 +146,8 @@ class TmpTestdir:
session.main() session.main()
config.pytestplugins.do_unconfigure(config) config.pytestplugins.do_unconfigure(config)
return sorter return sorter
finally:
def inline_run_with_plugins(self, *args): Node._setupstate = oldstate
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 config_preparse(self): def config_preparse(self):
config = self.Config() config = self.Config()