2 new changesets in pytest: http://bitbucket.org/hpk42/pytest/changeset/f27dab0f3a45/ changeset: r2196:f27dab0f3a45 user: hpk42 date: 2011-04-17 12:20:11 summary: fix issue38 - nicer tracebacks on sessionstart/configure (and other internal/custom hook failures) affected #: 4 files (1.0 KB)
--- a/CHANGELOG Sat Apr 16 00:47:16 2011 +0100 +++ b/CHANGELOG Sun Apr 17 12:20:11 2011 +0200 @@ -1,6 +1,9 @@ Changes between 2.0.2 and 2.0.3.dev ---------------------------------------------- +- fix issue38: nicer tracebacks on calls to hooks, particularly early + configure/sessionstart ones + - fix missing skip reason/meta information in junitxml files, reported via http://lists.idyll.org/pipermail/testing-in-python/2011-March/003928.html --- a/_pytest/core.py Sat Apr 16 00:47:16 2011 +0100 +++ b/_pytest/core.py Sun Apr 17 12:20:11 2011 +0200 @@ -265,8 +265,15 @@ config.hook.pytest_unconfigure(config=config) config.pluginmanager.unregister(self) - def notify_exception(self, excinfo): - excrepr = excinfo.getrepr(funcargs=True, showlocals=True) + def notify_exception(self, excinfo, option=None): + if option and option.fulltrace: + style = "long" + else: + style = "native" + excrepr = excinfo.getrepr(funcargs=True, + showlocals=getattr(option, 'showlocals', False), + style=style, + ) res = self.hook.pytest_internalerror(excrepr=excrepr) if not py.builtin.any(res): for line in str(excrepr).split("\n"): --- a/_pytest/main.py Sat Apr 16 00:47:16 2011 +0100 +++ b/_pytest/main.py Sun Apr 17 12:20:11 2011 +0200 @@ -71,7 +71,7 @@ session.exitstatus = EXIT_INTERRUPTED except: excinfo = py.code.ExceptionInfo() - config.pluginmanager.notify_exception(excinfo) + config.pluginmanager.notify_exception(excinfo, config.option) session.exitstatus = EXIT_INTERNALERROR if excinfo.errisinstance(SystemExit): sys.stderr.write("mainloop: caught Spurious SystemExit!\n") --- a/testing/acceptance_test.py Sat Apr 16 00:47:16 2011 +0100 +++ b/testing/acceptance_test.py Sun Apr 17 12:20:11 2011 +0200 @@ -13,6 +13,26 @@ '*ERROR: hello' ]) + def test_early_hook_error_issue38_1(self, testdir): + testdir.makeconftest(""" + def pytest_sessionstart(): + 0 / 0 + """) + result = testdir.runpytest(testdir.tmpdir) + assert result.ret != 0 + # tracestyle is native by default for hook failures + result.stdout.fnmatch_lines([ + '*INTERNALERROR*File*conftest.py*line 2*', + '*0 / 0*', + ]) + result = testdir.runpytest(testdir.tmpdir, "--fulltrace") + assert result.ret != 0 + # tracestyle is native by default for hook failures + result.stdout.fnmatch_lines([ + '*INTERNALERROR*def pytest_sessionstart():*', + '*INTERNALERROR*0 / 0*', + ]) + def test_file_not_found(self, testdir): result = testdir.runpytest("asd") assert result.ret != 0 http://bitbucket.org/hpk42/pytest/changeset/c8f97fe2247b/ changeset: r2197:c8f97fe2247b user: hpk42 date: 2011-04-17 12:20:13 summary: tentatively use internal list for cleanups at unconfigure time - this helps reporting with partially executed pytest_configure() hooks affected #: 7 files (678 bytes) --- a/_pytest/__init__.py Sun Apr 17 12:20:11 2011 +0200 +++ b/_pytest/__init__.py Sun Apr 17 12:20:13 2011 +0200 @@ -1,2 +1,2 @@ # -__version__ = '2.0.3.dev3' +__version__ = '2.0.3.dev4' --- a/_pytest/assertion.py Sun Apr 17 12:20:11 2011 +0200 +++ b/_pytest/assertion.py Sun Apr 17 12:20:13 2011 +0200 @@ -16,7 +16,8 @@ # py._code._assertionnew to detect this plugin was loaded and in # turn call the hooks defined here as part of the # DebugInterpreter. - config._monkeypatch = m = monkeypatch() + m = monkeypatch() + config._cleanup.append(m.undo) warn_about_missing_assertion() if not config.getvalue("noassert") and not config.getvalue("nomagic"): def callbinrepr(op, left, right): @@ -29,9 +30,6 @@ 'AssertionError', py.code._AssertionError) m.setattr(py.code, '_reprcompare', callbinrepr) -def pytest_unconfigure(config): - config._monkeypatch.undo() - def warn_about_missing_assertion(): try: assert False --- a/_pytest/config.py Sun Apr 17 12:20:11 2011 +0200 +++ b/_pytest/config.py Sun Apr 17 12:20:13 2011 +0200 @@ -12,6 +12,10 @@ config.trace.root.setwriter(sys.stderr.write) return config +def pytest_unconfigure(config): + for func in config._cleanup: + func() + class Parser: """ Parser for command line arguments. """ @@ -251,7 +255,8 @@ self._conftest = Conftest(onimport=self._onimportconftest) self.hook = self.pluginmanager.hook self._inicache = {} - + self._cleanup = [] + @classmethod def fromdictargs(cls, option_dict, args): """ constructor useable for subprocesses. """ --- a/_pytest/tmpdir.py Sun Apr 17 12:20:11 2011 +0200 +++ b/_pytest/tmpdir.py Sun Apr 17 12:20:13 2011 +0200 @@ -48,15 +48,12 @@ self.trace("finish") def pytest_configure(config): - config._mp = mp = monkeypatch() + mp = monkeypatch() t = TempdirHandler(config) + config._cleanup.extend([mp.undo, t.finish]) mp.setattr(config, '_tmpdirhandler', t, raising=False) mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False) -def pytest_unconfigure(config): - config._tmpdirhandler.finish() - config._mp.undo() - def pytest_funcarg__tmpdir(request): """return a temporary directory path object which is unique to each test function invocation, --- a/setup.py Sun Apr 17 12:20:11 2011 +0200 +++ b/setup.py Sun Apr 17 12:20:13 2011 +0200 @@ -22,7 +22,7 @@ name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.3.dev3', + version='2.0.3.dev4', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], --- a/testing/acceptance_test.py Sun Apr 17 12:20:11 2011 +0200 +++ b/testing/acceptance_test.py Sun Apr 17 12:20:13 2011 +0200 @@ -33,6 +33,19 @@ '*INTERNALERROR*0 / 0*', ]) + def test_early_hook_configure_error_issue38(self, testdir): + testdir.makeconftest(""" + def pytest_configure(): + 0 / 0 + """) + result = testdir.runpytest(testdir.tmpdir) + assert result.ret != 0 + # here we get it on stderr + result.stderr.fnmatch_lines([ + '*INTERNALERROR*File*conftest.py*line 2*', + '*0 / 0*', + ]) + def test_file_not_found(self, testdir): result = testdir.runpytest("asd") assert result.ret != 0 --- a/testing/test_assertion.py Sun Apr 17 12:20:11 2011 +0200 +++ b/testing/test_assertion.py Sun Apr 17 12:20:13 2011 +0200 @@ -44,7 +44,8 @@ config = testdir.parseconfig() plugin.pytest_configure(config) assert hook != py.code._reprcompare - plugin.pytest_unconfigure(config) + from _pytest.config import pytest_unconfigure + pytest_unconfigure(config) assert hook == py.code._reprcompare def callequal(left, right): Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn