From 31576fac61cd1ed0b943d1d86ac559055005bb72 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 Nov 2013 14:19:29 +0100 Subject: [PATCH] fix issue380 by making --resultlog only rely on longrepr instead of the "reprcrash" attribute which only exists sometimes. --- CHANGELOG | 3 +++ _pytest/resultlog.py | 4 ++-- testing/test_resultlog.py | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 354553594..8f78c5e75 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,9 @@ Unreleased since the unittest compat enhancements allow trial to handle it on its own +- fix issue380 by making --resultlog only rely on longrepr instead + of the "reprcrash" attribute which only exists sometimes. + - fix pexpect-3.0 compatibility for pytest's own tests. (fixes issue386) diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index d7f37a53c..0c100552f 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -6,7 +6,7 @@ import py def pytest_addoption(parser): group = parser.getgroup("terminal reporting", "resultlog plugin options") - group.addoption('--resultlog', '--result-log', action="store", + group.addoption('--resultlog', '--result-log', action="store", metavar="path", default=None, help="path for machine-readable result log.") @@ -85,7 +85,7 @@ class ResultLog(object): if not report.passed: if report.failed: code = "F" - longrepr = str(report.longrepr.reprcrash) + longrepr = str(report.longrepr) else: assert report.skipped code = "S" diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index 9a3bb6465..e4f3faccc 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -195,3 +195,23 @@ def test_no_resultlog_on_slaves(testdir): pytest_unconfigure(config) assert not hasattr(config, '_resultlog') + +def test_failure_issue380(testdir): + testdir.makeconftest(""" + import pytest + class MyCollector(pytest.File): + def collect(self): + raise ValueError() + def repr_failure(self, excinfo): + return "somestring" + def pytest_collect_file(path, parent): + return MyCollector(parent=parent, fspath=path) + """) + testdir.makepyfile(""" + def test_func(): + pass + """) + result = testdir.runpytest("--resultlog=log") + assert result.ret == 1 + +