diff --git a/py/test/dsession/testing/test_functional_dsession.py b/py/test/dsession/testing/test_functional_dsession.py index 20a3e46b3..cd47828e4 100644 --- a/py/test/dsession/testing/test_functional_dsession.py +++ b/py/test/dsession/testing/test_functional_dsession.py @@ -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 diff --git a/py/test/plugin/pytest_doctest.py b/py/test/plugin/pytest_doctest.py index e4e32661d..90abadbfe 100644 --- a/py/test/plugin/pytest_doctest.py +++ b/py/test/plugin/pytest_doctest.py @@ -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 diff --git a/py/test/plugin/pytest_pocoo.py b/py/test/plugin/pytest_pocoo.py index 8fc32e07e..78534fa96 100644 --- a/py/test/plugin/pytest_pocoo.py +++ b/py/test/plugin/pytest_pocoo.py @@ -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] + diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 7b1a0000f..30e96afd5 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -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()