From 5c8df1d4cac111871bae8fcc0e7c44ab72aca2b2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 9 Aug 2009 23:46:27 +0200 Subject: [PATCH] turn some tests from skipped to xfail strike dead code, small refinements to xfail exception reporting --HG-- branch : 1.0.x --- py/code/excinfo.py | 3 +-- py/code/testing/test_excinfo.py | 6 +++++- py/code/testing/test_source.py | 4 ++-- py/test/plugin/pytest_xfail.py | 6 ++++-- py/test/pluginmanager.py | 3 --- py/test/testing/test_pluginmanager.py | 11 ++++++++++- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/py/code/excinfo.py b/py/code/excinfo.py index 52fe04b51..4245f7fe5 100644 --- a/py/code/excinfo.py +++ b/py/code/excinfo.py @@ -39,8 +39,7 @@ class ExceptionInfo(object): """ lines = py.std.traceback.format_exception_only(self.type, self.value) text = ''.join(lines) - if text.endswith('\n'): - text = text[:-1] + text = text.rstrip() if tryshort: if text.startswith(self._striptext): text = text[len(self._striptext):] diff --git a/py/code/testing/test_excinfo.py b/py/code/testing/test_excinfo.py index 2d1b43661..4d831c580 100644 --- a/py/code/testing/test_excinfo.py +++ b/py/code/testing/test_excinfo.py @@ -200,6 +200,11 @@ def test_tbentry_reinterpret(): def test_excinfo_exconly(): excinfo = py.test.raises(ValueError, h) assert excinfo.exconly().startswith('ValueError') + excinfo = py.test.raises(ValueError, + "raise ValueError('hello\\nworld')") + msg = excinfo.exconly(tryshort=True) + assert msg.startswith('ValueError') + assert msg.endswith("world") def test_excinfo_repr(): excinfo = py.test.raises(ValueError, h) @@ -242,7 +247,6 @@ def test_entrysource_Queue_example(): assert s.startswith("def get") def test_codepath_Queue_example(): - py.test.skip("try harder to get at the paths of code objects.") import Queue try: Queue.Queue().get(timeout=0.001) diff --git a/py/code/testing/test_source.py b/py/code/testing/test_source.py index 641b26fd4..ffb00200c 100644 --- a/py/code/testing/test_source.py +++ b/py/code/testing/test_source.py @@ -173,8 +173,8 @@ class TestSourceParsingAndCompiling: assert len(source) == 6 assert source.getstatementrange(2) == (1, 4) + @py.test.mark.xfail def test_getstatementrange_bug2(self): - py.test.skip("fix me (issue19)") source = Source("""\ assert ( 33 @@ -300,8 +300,8 @@ def test_deindent(): lines = deindent(source.splitlines()) assert lines == ['', 'def f():', ' def g():', ' pass', ' '] +@py.test.mark.xfail def test_source_of_class_at_eof_without_newline(): - py.test.skip("CPython's inspect.getsource is buggy") # this test fails because the implicit inspect.getsource(A) below # does not return the "x = 1" last line. tmpdir = py.test.ensuretemp("source_write_read") diff --git a/py/test/plugin/pytest_xfail.py b/py/test/plugin/pytest_xfail.py index be85e8721..8e6a3b73c 100644 --- a/py/test/plugin/pytest_xfail.py +++ b/py/test/plugin/pytest_xfail.py @@ -19,8 +19,6 @@ when it fails. Instead terminal reporting will list it in the import py -pytest_plugins = ['keyword'] - def pytest_runtest_makereport(__call__, item, call): if call.when != "call": return @@ -53,6 +51,9 @@ def pytest_terminal_summary(terminalreporter): modpath = rep.item.getmodpath(includemodule=True) pos = "%s %s:%d: " %(modpath, entry.path, entry.lineno) reason = rep.longrepr.reprcrash.message + i = reason.find("\n") + if i != -1: + reason = reason[:i] tr._tw.line("%s %s" %(pos, reason)) xpassed = terminalreporter.stats.get("xpassed") @@ -89,3 +90,4 @@ def test_xfail(testdir): "*test_that*", ]) assert result.ret == 1 + diff --git a/py/test/pluginmanager.py b/py/test/pluginmanager.py index d9c6860a2..c9e946b6e 100644 --- a/py/test/pluginmanager.py +++ b/py/test/pluginmanager.py @@ -200,9 +200,6 @@ class PluginManager(object): config.hook.pytest_unconfigure(config=config) config.pluginmanager.unregister(self) -class Ext: - """ namespace for extension objects. """ - # # XXX old code to automatically load classes # diff --git a/py/test/testing/test_pluginmanager.py b/py/test/testing/test_pluginmanager.py index a4ea7f27d..8365652f9 100644 --- a/py/test/testing/test_pluginmanager.py +++ b/py/test/testing/test_pluginmanager.py @@ -185,7 +185,7 @@ class TestPytestPluginInteractions: assert hello == "world" """) result = testdir.runpytest(p) - assert result.stdout.fnmatch_lines([ + result.stdout.fnmatch_lines([ "*1 passed*" ]) @@ -247,3 +247,12 @@ def test_collectattr(): assert list(methods) == ['pytest_hello', 'pytest_world'] methods = py.builtin.sorted(collectattr(B())) assert list(methods) == ['pytest_hello', 'pytest_world'] + +@py.test.mark.xfail +def test_namespace_has_default_and_env_plugins(testdir): + p = testdir.makepyfile(""" + import py + py.test.mark + """) + result = testdir.runpython(p) + assert result.ret == 0