From 1a570011fec48c2a71092408b18869a7b8ba013b Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 3 Aug 2009 16:01:32 +0200 Subject: [PATCH] showing relative paths by default, improving xfail output a bit, bumping version info to 1.0.0 --HG-- branch : 1.0.x --- MANIFEST | 13 +++++++------ doc/test/plugin/index.txt | 2 +- doc/test/plugin/links.txt | 28 ++++++++++++++-------------- doc/test/plugin/terminal.txt | 15 +++++++++++++++ doc/test/plugin/xfail.txt | 6 +++--- py/__init__.py | 2 +- py/code/excinfo.py | 23 +++++++++++++++++------ py/code/testing/test_excinfo.py | 21 +++++++++++++++++++++ py/test/plugin/pytest_xfail.py | 32 +++++++++++++++++--------------- setup.py | 2 +- 10 files changed, 97 insertions(+), 47 deletions(-) diff --git a/MANIFEST b/MANIFEST index 90fa7a29f..670f422d9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -28,17 +28,18 @@ doc/test/examples.txt doc/test/extend.txt doc/test/features.txt doc/test/funcargs.txt +doc/test/plugin/capture.txt doc/test/plugin/doctest.txt doc/test/plugin/figleaf.txt doc/test/plugin/hooklog.txt doc/test/plugin/hookspec.txt doc/test/plugin/index.txt -doc/test/plugin/iocapture.txt doc/test/plugin/keyword.txt +doc/test/plugin/links.txt doc/test/plugin/monkeypatch.txt doc/test/plugin/oejskit.txt +doc/test/plugin/pastebin.txt doc/test/plugin/pdb.txt -doc/test/plugin/pocoo.txt doc/test/plugin/recwarn.txt doc/test/plugin/restdoc.txt doc/test/plugin/resultlog.txt @@ -315,6 +316,7 @@ py/test/dist/dsession.py py/test/dist/mypickle.py py/test/dist/nodemanage.py py/test/dist/testing/__init__.py +py/test/dist/testing/acceptance_test.py py/test/dist/testing/test_dsession.py py/test/dist/testing/test_mypickle.py py/test/dist/testing/test_nodemanage.py @@ -333,28 +335,27 @@ py/test/plugin/__init__.py py/test/plugin/conftest.py py/test/plugin/hookspec.py py/test/plugin/pytest__pytest.py +py/test/plugin/pytest_capture.py py/test/plugin/pytest_default.py py/test/plugin/pytest_doctest.py py/test/plugin/pytest_execnetcleanup.py py/test/plugin/pytest_figleaf.py py/test/plugin/pytest_hooklog.py -py/test/plugin/pytest_iocapture.py py/test/plugin/pytest_keyword.py py/test/plugin/pytest_monkeypatch.py +py/test/plugin/pytest_pastebin.py py/test/plugin/pytest_pdb.py -py/test/plugin/pytest_pocoo.py py/test/plugin/pytest_pylint.py py/test/plugin/pytest_pytester.py py/test/plugin/pytest_recwarn.py py/test/plugin/pytest_restdoc.py -py/test/plugin/pytest_resultdb.py py/test/plugin/pytest_resultlog.py py/test/plugin/pytest_runner.py py/test/plugin/pytest_terminal.py py/test/plugin/pytest_tmpdir.py py/test/plugin/pytest_unittest.py py/test/plugin/pytest_xfail.py -py/test/plugin/test_pytest_iocapture.py +py/test/plugin/test_pytest_capture.py py/test/plugin/test_pytest_runner.py py/test/plugin/test_pytest_runner_xunit.py py/test/plugin/test_pytest_terminal.py diff --git a/doc/test/plugin/index.txt b/doc/test/plugin/index.txt index 2eb199651..84f93d37b 100644 --- a/doc/test/plugin/index.txt +++ b/doc/test/plugin/index.txt @@ -2,7 +2,7 @@ Plugins related to Python test functions and programs ===================================================== -xfail_ mark python tests as expected-to-fail and report them separately. +xfail_ mark python test functions as expected-to-fail and report them separately. figleaf_ write and report coverage data with 'figleaf'. diff --git a/doc/test/plugin/links.txt b/doc/test/plugin/links.txt index 3933afaf3..00fc9bf2a 100644 --- a/doc/test/plugin/links.txt +++ b/doc/test/plugin/links.txt @@ -1,33 +1,33 @@ .. _`terminal`: terminal.html -.. _`pytest_recwarn.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_recwarn.py +.. _`pytest_recwarn.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_recwarn.py .. _`unittest`: unittest.html -.. _`pytest_monkeypatch.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_monkeypatch.py -.. _`pytest_keyword.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_keyword.py +.. _`pytest_monkeypatch.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_monkeypatch.py +.. _`pytest_keyword.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_keyword.py .. _`pastebin`: pastebin.html .. _`plugins`: index.html -.. _`pytest_capture.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_capture.py -.. _`pytest_doctest.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_doctest.py +.. _`pytest_capture.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_capture.py +.. _`pytest_doctest.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_doctest.py .. _`capture`: capture.html .. _`hooklog`: hooklog.html -.. _`pytest_restdoc.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_restdoc.py -.. _`pytest_hooklog.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_hooklog.py -.. _`pytest_pastebin.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_pastebin.py -.. _`pytest_figleaf.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_figleaf.py +.. _`pytest_restdoc.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_restdoc.py +.. _`pytest_hooklog.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_hooklog.py +.. _`pytest_pastebin.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_pastebin.py +.. _`pytest_figleaf.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_figleaf.py .. _`xfail`: xfail.html .. _`contact`: ../../contact.html .. _`checkout the py.test development version`: ../../download.html#checkout .. _`oejskit`: oejskit.html -.. _`pytest_xfail.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_xfail.py +.. _`pytest_xfail.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_xfail.py .. _`figleaf`: figleaf.html .. _`extend`: ../extend.html -.. _`pytest_terminal.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_terminal.py +.. _`pytest_terminal.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_terminal.py .. _`recwarn`: recwarn.html -.. _`pytest_pdb.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_pdb.py +.. _`pytest_pdb.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_pdb.py .. _`monkeypatch`: monkeypatch.html .. _`resultlog`: resultlog.html .. _`keyword`: keyword.html .. _`restdoc`: restdoc.html -.. _`pytest_unittest.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_unittest.py +.. _`pytest_unittest.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_unittest.py .. _`doctest`: doctest.html -.. _`pytest_resultlog.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_resultlog.py +.. _`pytest_resultlog.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_resultlog.py .. _`pdb`: pdb.html diff --git a/doc/test/plugin/terminal.txt b/doc/test/plugin/terminal.txt index ab6cde48c..20f999153 100644 --- a/doc/test/plugin/terminal.txt +++ b/doc/test/plugin/terminal.txt @@ -9,6 +9,21 @@ Implements terminal reporting of the full testing process. This is a good source for looking at the various reporting hooks. +command line options +-------------------- + + +``--collectonly`` + only collect tests, don't execute them. +``--traceconfig`` + trace considerations of conftest.py files. +``--nomagic`` + don't reinterpret asserts, no traceback cutting. +``--fulltrace`` + don't cut any tracebacks (default is to cut). +``--debug`` + generate and show debugging information. + Start improving this plugin in 30 seconds ========================================= diff --git a/doc/test/plugin/xfail.txt b/doc/test/plugin/xfail.txt index 4764a224d..8e5dd72af 100644 --- a/doc/test/plugin/xfail.txt +++ b/doc/test/plugin/xfail.txt @@ -2,7 +2,7 @@ pytest_xfail plugin =================== -mark python tests as expected-to-fail and report them separately. +mark python test functions as expected-to-fail and report them separately. .. contents:: :local: @@ -10,8 +10,8 @@ mark python tests as expected-to-fail and report them separately. usage ------------ -Use the generic mark decorator to add the 'xfail' keyword to your -test function:: +Use the generic mark decorator to mark your test functions as +'expected to fail':: @py.test.mark.xfail def test_hello(): diff --git a/py/__init__.py b/py/__init__.py index b75980bba..e75dd1b7f 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -20,7 +20,7 @@ For questions please check out http://pylib.org/contact.html from initpkg import initpkg trunk = None -version = trunk or "1.0.0b9" +version = trunk or "1.0.0" initpkg(__name__, description = "py.test and pylib: advanced testing tool and networking lib", diff --git a/py/code/excinfo.py b/py/code/excinfo.py index 543e0a5b0..52fe04b51 100644 --- a/py/code/excinfo.py +++ b/py/code/excinfo.py @@ -57,14 +57,15 @@ class ExceptionInfo(object): reprcrash = ReprFileLocation(path, lineno+1, exconly) return reprcrash - def getrepr(self, showlocals=False, style="long", tbfilter=True, funcargs=False): + def getrepr(self, showlocals=False, style="long", + abspath=False, tbfilter=True, funcargs=False): """ return str()able representation of this exception info. showlocals: show locals per traceback entry style: long|short|no traceback style tbfilter: hide entries (where __tracebackhide__ is true) """ fmt = FormattedExcinfo(showlocals=showlocals, style=style, - tbfilter=tbfilter, funcargs=funcargs) + abspath=abspath, tbfilter=tbfilter, funcargs=funcargs) return fmt.repr_excinfo(self) def __str__(self): @@ -78,11 +79,12 @@ class FormattedExcinfo(object): flow_marker = ">" fail_marker = "E" - def __init__(self, showlocals=False, style="long", tbfilter=True, funcargs=False): + def __init__(self, showlocals=False, style="long", abspath=True, tbfilter=True, funcargs=False): self.showlocals = showlocals self.style = style self.tbfilter = tbfilter self.funcargs = funcargs + self.abspath = abspath def _getindent(self, source): # figure out indent for given source @@ -154,8 +156,9 @@ class FormattedExcinfo(object): if name == '__builtins__': lines.append("__builtins__ = ") else: - # This formatting could all be handled by the _repr() function, which is - # only repr.Repr in disguise, so is very configurable. + # This formatting could all be handled by the + # _repr() function, which is only repr.Repr in + # disguise, so is very configurable. str_repr = self._saferepr(value) #if len(str_repr) < 70 or not isinstance(value, # (list, tuple, dict)): @@ -180,7 +183,8 @@ class FormattedExcinfo(object): reprargs = self.repr_args(entry) lines.extend(self.get_source(source, line_index, excinfo)) message = excinfo and excinfo.typename or "" - filelocrepr = ReprFileLocation(entry.path, entry.lineno+1, message) + path = self._makepath(entry.path) + filelocrepr = ReprFileLocation(path, entry.lineno+1, message) localsrepr = self.repr_locals(entry.locals) return ReprEntry(lines, reprargs, localsrepr, filelocrepr) else: @@ -193,6 +197,13 @@ class FormattedExcinfo(object): lines.extend(self.get_exconly(excinfo, indent=4)) return ReprEntry(lines, None, None, None) + def _makepath(self, path): + if not self.abspath: + np = py.path.local().bestrelpath(path) + if len(np) < len(str(path)): + path = np + return path + def repr_traceback(self, excinfo): traceback = excinfo.traceback if self.tbfilter: diff --git a/py/code/testing/test_excinfo.py b/py/code/testing/test_excinfo.py index 9341fe61f..e53e3eb90 100644 --- a/py/code/testing/test_excinfo.py +++ b/py/code/testing/test_excinfo.py @@ -625,6 +625,27 @@ raise ValueError() assert tw.lines[9] == "" assert tw.lines[10].endswith("mod.py:3: ValueError") + def test_toterminal_long_filenames(self): + mod = self.importasmod(""" + def f(): + raise ValueError() + """) + excinfo = py.test.raises(ValueError, mod.f) + tw = TWMock() + path = py.path.local(mod.__file__) + old = path.dirpath().chdir() + try: + repr = excinfo.getrepr(abspath=False) + repr.toterminal(tw) + line = tw.lines[-1] + assert line == "mod.py:3: ValueError" + + repr = excinfo.getrepr(abspath=True) + repr.toterminal(tw) + line = tw.lines[-1] + assert line == "%s:3: ValueError" %(path,) + finally: + old.chdir() def test_format_excinfo(self): mod = self.importasmod(""" diff --git a/py/test/plugin/pytest_xfail.py b/py/test/plugin/pytest_xfail.py index 1bf8b5157..b05292ea7 100644 --- a/py/test/plugin/pytest_xfail.py +++ b/py/test/plugin/pytest_xfail.py @@ -1,11 +1,11 @@ """ -mark python tests as expected-to-fail and report them separately. +mark python test functions as expected-to-fail and report them separately. usage ------------ -Use the generic mark decorator to add the 'xfail' keyword to your -test function:: +Use the generic mark decorator to mark your test functions as +'expected to fail':: @py.test.mark.xfail def test_hello(): @@ -14,6 +14,7 @@ test function:: This test will be executed but no traceback will be reported when it fails. Instead terminal reporting will list it in the "expected to fail" section or "unexpectedly passing" section. + """ import py @@ -48,28 +49,29 @@ def pytest_terminal_summary(terminalreporter): xfailed = tr.stats.get("xfailed") if xfailed: tr.write_sep("_", "expected failures") - for event in xfailed: - entry = event.longrepr.reprcrash - key = entry.path, entry.lineno, entry.message - reason = event.longrepr.reprcrash.message - modpath = event.item.getmodpath(includemodule=True) - #tr._tw.line("%s %s:%d: %s" %(modpath, entry.path, entry.lineno, entry.message)) - tr._tw.line("%s %s:%d: " %(modpath, entry.path, entry.lineno)) + for rep in xfailed: + entry = rep.longrepr.reprcrash + modpath = rep.item.getmodpath(includemodule=True) + pos = "%s %s:%d: " %(modpath, entry.path, entry.lineno) + reason = rep.longrepr.reprcrash.message + tr._tw.line("%s %s" %(pos, reason)) xpassed = terminalreporter.stats.get("xpassed") if xpassed: tr.write_sep("_", "UNEXPECTEDLY PASSING TESTS") - for event in xpassed: - tr._tw.line("%s: xpassed" %(event.item,)) + for rep in xpassed: + fspath, lineno, modpath = rep.item.reportinfo() + pos = "%s %s:%d: unexpectedly passing" %(modpath, fspath, lineno) + tr._tw.line(pos) -# =============================================================================== +# ============================================================================= # # plugin tests # -# =============================================================================== +# ============================================================================= -def test_xfail(testdir, linecomp): +def test_xfail(testdir): p = testdir.makepyfile(test_one=""" import py @py.test.mark.xfail diff --git a/setup.py b/setup.py index 4b94ca098..06e1f6d95 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def main(): name='py', description='py.test and pylib: advanced testing tool and networking lib', long_description = long_description, - version= trunk or '1.0.0b9', + version= trunk or '1.0.0', url='http://pylib.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],