showing relative paths by default, improving xfail output a bit, bumping version info to 1.0.0

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-08-03 16:01:32 +02:00
parent 30d77f77af
commit 1a570011fe
10 changed files with 97 additions and 47 deletions

View File

@ -28,17 +28,18 @@ doc/test/examples.txt
doc/test/extend.txt doc/test/extend.txt
doc/test/features.txt doc/test/features.txt
doc/test/funcargs.txt doc/test/funcargs.txt
doc/test/plugin/capture.txt
doc/test/plugin/doctest.txt doc/test/plugin/doctest.txt
doc/test/plugin/figleaf.txt doc/test/plugin/figleaf.txt
doc/test/plugin/hooklog.txt doc/test/plugin/hooklog.txt
doc/test/plugin/hookspec.txt doc/test/plugin/hookspec.txt
doc/test/plugin/index.txt doc/test/plugin/index.txt
doc/test/plugin/iocapture.txt
doc/test/plugin/keyword.txt doc/test/plugin/keyword.txt
doc/test/plugin/links.txt
doc/test/plugin/monkeypatch.txt doc/test/plugin/monkeypatch.txt
doc/test/plugin/oejskit.txt doc/test/plugin/oejskit.txt
doc/test/plugin/pastebin.txt
doc/test/plugin/pdb.txt doc/test/plugin/pdb.txt
doc/test/plugin/pocoo.txt
doc/test/plugin/recwarn.txt doc/test/plugin/recwarn.txt
doc/test/plugin/restdoc.txt doc/test/plugin/restdoc.txt
doc/test/plugin/resultlog.txt doc/test/plugin/resultlog.txt
@ -315,6 +316,7 @@ py/test/dist/dsession.py
py/test/dist/mypickle.py py/test/dist/mypickle.py
py/test/dist/nodemanage.py py/test/dist/nodemanage.py
py/test/dist/testing/__init__.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_dsession.py
py/test/dist/testing/test_mypickle.py py/test/dist/testing/test_mypickle.py
py/test/dist/testing/test_nodemanage.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/conftest.py
py/test/plugin/hookspec.py py/test/plugin/hookspec.py
py/test/plugin/pytest__pytest.py py/test/plugin/pytest__pytest.py
py/test/plugin/pytest_capture.py
py/test/plugin/pytest_default.py py/test/plugin/pytest_default.py
py/test/plugin/pytest_doctest.py py/test/plugin/pytest_doctest.py
py/test/plugin/pytest_execnetcleanup.py py/test/plugin/pytest_execnetcleanup.py
py/test/plugin/pytest_figleaf.py py/test/plugin/pytest_figleaf.py
py/test/plugin/pytest_hooklog.py py/test/plugin/pytest_hooklog.py
py/test/plugin/pytest_iocapture.py
py/test/plugin/pytest_keyword.py py/test/plugin/pytest_keyword.py
py/test/plugin/pytest_monkeypatch.py py/test/plugin/pytest_monkeypatch.py
py/test/plugin/pytest_pastebin.py
py/test/plugin/pytest_pdb.py py/test/plugin/pytest_pdb.py
py/test/plugin/pytest_pocoo.py
py/test/plugin/pytest_pylint.py py/test/plugin/pytest_pylint.py
py/test/plugin/pytest_pytester.py py/test/plugin/pytest_pytester.py
py/test/plugin/pytest_recwarn.py py/test/plugin/pytest_recwarn.py
py/test/plugin/pytest_restdoc.py py/test/plugin/pytest_restdoc.py
py/test/plugin/pytest_resultdb.py
py/test/plugin/pytest_resultlog.py py/test/plugin/pytest_resultlog.py
py/test/plugin/pytest_runner.py py/test/plugin/pytest_runner.py
py/test/plugin/pytest_terminal.py py/test/plugin/pytest_terminal.py
py/test/plugin/pytest_tmpdir.py py/test/plugin/pytest_tmpdir.py
py/test/plugin/pytest_unittest.py py/test/plugin/pytest_unittest.py
py/test/plugin/pytest_xfail.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.py
py/test/plugin/test_pytest_runner_xunit.py py/test/plugin/test_pytest_runner_xunit.py
py/test/plugin/test_pytest_terminal.py py/test/plugin/test_pytest_terminal.py

View File

@ -2,7 +2,7 @@
Plugins related to Python test functions and programs 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'. figleaf_ write and report coverage data with 'figleaf'.

View File

@ -1,33 +1,33 @@
.. _`terminal`: terminal.html .. _`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 .. _`unittest`: unittest.html
.. _`pytest_monkeypatch.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_monkeypatch.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/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_keyword.py .. _`pytest_keyword.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_keyword.py
.. _`pastebin`: pastebin.html .. _`pastebin`: pastebin.html
.. _`plugins`: index.html .. _`plugins`: index.html
.. _`pytest_capture.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_capture.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/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_doctest.py .. _`pytest_doctest.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_doctest.py
.. _`capture`: capture.html .. _`capture`: capture.html
.. _`hooklog`: hooklog.html .. _`hooklog`: hooklog.html
.. _`pytest_restdoc.py`: http://bitbucket.org/hpk42/py-trunk/raw/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_restdoc.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/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_hooklog.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/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_pastebin.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/e9bce7c38c26d789a83bc0e9db7c4b8366e44cc1/py/test/plugin/pytest_figleaf.py .. _`pytest_figleaf.py`: http://bitbucket.org/hpk42/py-trunk/raw/4ac3aa2d7ea5f3fdcb5a28d4ca70040d9180ef04/py/test/plugin/pytest_figleaf.py
.. _`xfail`: xfail.html .. _`xfail`: xfail.html
.. _`contact`: ../../contact.html .. _`contact`: ../../contact.html
.. _`checkout the py.test development version`: ../../download.html#checkout .. _`checkout the py.test development version`: ../../download.html#checkout
.. _`oejskit`: oejskit.html .. _`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 .. _`figleaf`: figleaf.html
.. _`extend`: ../extend.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 .. _`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 .. _`monkeypatch`: monkeypatch.html
.. _`resultlog`: resultlog.html .. _`resultlog`: resultlog.html
.. _`keyword`: keyword.html .. _`keyword`: keyword.html
.. _`restdoc`: restdoc.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 .. _`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 .. _`pdb`: pdb.html

View File

@ -9,6 +9,21 @@ Implements terminal reporting of the full testing process.
This is a good source for looking at the various reporting hooks. 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 Start improving this plugin in 30 seconds
========================================= =========================================

View File

@ -2,7 +2,7 @@
pytest_xfail plugin 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:: .. contents::
:local: :local:
@ -10,8 +10,8 @@ mark python tests as expected-to-fail and report them separately.
usage usage
------------ ------------
Use the generic mark decorator to add the 'xfail' keyword to your Use the generic mark decorator to mark your test functions as
test function:: 'expected to fail'::
@py.test.mark.xfail @py.test.mark.xfail
def test_hello(): def test_hello():

View File

@ -20,7 +20,7 @@ For questions please check out http://pylib.org/contact.html
from initpkg import initpkg from initpkg import initpkg
trunk = None trunk = None
version = trunk or "1.0.0b9" version = trunk or "1.0.0"
initpkg(__name__, initpkg(__name__,
description = "py.test and pylib: advanced testing tool and networking lib", description = "py.test and pylib: advanced testing tool and networking lib",

View File

@ -57,14 +57,15 @@ class ExceptionInfo(object):
reprcrash = ReprFileLocation(path, lineno+1, exconly) reprcrash = ReprFileLocation(path, lineno+1, exconly)
return reprcrash 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. """ return str()able representation of this exception info.
showlocals: show locals per traceback entry showlocals: show locals per traceback entry
style: long|short|no traceback style style: long|short|no traceback style
tbfilter: hide entries (where __tracebackhide__ is true) tbfilter: hide entries (where __tracebackhide__ is true)
""" """
fmt = FormattedExcinfo(showlocals=showlocals, style=style, fmt = FormattedExcinfo(showlocals=showlocals, style=style,
tbfilter=tbfilter, funcargs=funcargs) abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
return fmt.repr_excinfo(self) return fmt.repr_excinfo(self)
def __str__(self): def __str__(self):
@ -78,11 +79,12 @@ class FormattedExcinfo(object):
flow_marker = ">" flow_marker = ">"
fail_marker = "E" 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.showlocals = showlocals
self.style = style self.style = style
self.tbfilter = tbfilter self.tbfilter = tbfilter
self.funcargs = funcargs self.funcargs = funcargs
self.abspath = abspath
def _getindent(self, source): def _getindent(self, source):
# figure out indent for given source # figure out indent for given source
@ -154,8 +156,9 @@ class FormattedExcinfo(object):
if name == '__builtins__': if name == '__builtins__':
lines.append("__builtins__ = <builtins>") lines.append("__builtins__ = <builtins>")
else: else:
# This formatting could all be handled by the _repr() function, which is # This formatting could all be handled by the
# only repr.Repr in disguise, so is very configurable. # _repr() function, which is only repr.Repr in
# disguise, so is very configurable.
str_repr = self._saferepr(value) str_repr = self._saferepr(value)
#if len(str_repr) < 70 or not isinstance(value, #if len(str_repr) < 70 or not isinstance(value,
# (list, tuple, dict)): # (list, tuple, dict)):
@ -180,7 +183,8 @@ class FormattedExcinfo(object):
reprargs = self.repr_args(entry) reprargs = self.repr_args(entry)
lines.extend(self.get_source(source, line_index, excinfo)) lines.extend(self.get_source(source, line_index, excinfo))
message = excinfo and excinfo.typename or "" 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) localsrepr = self.repr_locals(entry.locals)
return ReprEntry(lines, reprargs, localsrepr, filelocrepr) return ReprEntry(lines, reprargs, localsrepr, filelocrepr)
else: else:
@ -193,6 +197,13 @@ class FormattedExcinfo(object):
lines.extend(self.get_exconly(excinfo, indent=4)) lines.extend(self.get_exconly(excinfo, indent=4))
return ReprEntry(lines, None, None, None) 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): def repr_traceback(self, excinfo):
traceback = excinfo.traceback traceback = excinfo.traceback
if self.tbfilter: if self.tbfilter:

View File

@ -625,6 +625,27 @@ raise ValueError()
assert tw.lines[9] == "" assert tw.lines[9] == ""
assert tw.lines[10].endswith("mod.py:3: ValueError") 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): def test_format_excinfo(self):
mod = self.importasmod(""" mod = self.importasmod("""

View File

@ -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 usage
------------ ------------
Use the generic mark decorator to add the 'xfail' keyword to your Use the generic mark decorator to mark your test functions as
test function:: 'expected to fail'::
@py.test.mark.xfail @py.test.mark.xfail
def test_hello(): def test_hello():
@ -14,6 +14,7 @@ test function::
This test will be executed but no traceback will be reported This test will be executed but no traceback will be reported
when it fails. Instead terminal reporting will list it in the when it fails. Instead terminal reporting will list it in the
"expected to fail" section or "unexpectedly passing" section. "expected to fail" section or "unexpectedly passing" section.
""" """
import py import py
@ -48,28 +49,29 @@ def pytest_terminal_summary(terminalreporter):
xfailed = tr.stats.get("xfailed") xfailed = tr.stats.get("xfailed")
if xfailed: if xfailed:
tr.write_sep("_", "expected failures") tr.write_sep("_", "expected failures")
for event in xfailed: for rep in xfailed:
entry = event.longrepr.reprcrash entry = rep.longrepr.reprcrash
key = entry.path, entry.lineno, entry.message modpath = rep.item.getmodpath(includemodule=True)
reason = event.longrepr.reprcrash.message pos = "%s %s:%d: " %(modpath, entry.path, entry.lineno)
modpath = event.item.getmodpath(includemodule=True) reason = rep.longrepr.reprcrash.message
#tr._tw.line("%s %s:%d: %s" %(modpath, entry.path, entry.lineno, entry.message)) tr._tw.line("%s %s" %(pos, reason))
tr._tw.line("%s %s:%d: " %(modpath, entry.path, entry.lineno))
xpassed = terminalreporter.stats.get("xpassed") xpassed = terminalreporter.stats.get("xpassed")
if xpassed: if xpassed:
tr.write_sep("_", "UNEXPECTEDLY PASSING TESTS") tr.write_sep("_", "UNEXPECTEDLY PASSING TESTS")
for event in xpassed: for rep in xpassed:
tr._tw.line("%s: xpassed" %(event.item,)) fspath, lineno, modpath = rep.item.reportinfo()
pos = "%s %s:%d: unexpectedly passing" %(modpath, fspath, lineno)
tr._tw.line(pos)
# =============================================================================== # =============================================================================
# #
# plugin tests # plugin tests
# #
# =============================================================================== # =============================================================================
def test_xfail(testdir, linecomp): def test_xfail(testdir):
p = testdir.makepyfile(test_one=""" p = testdir.makepyfile(test_one="""
import py import py
@py.test.mark.xfail @py.test.mark.xfail

View File

@ -31,7 +31,7 @@ def main():
name='py', name='py',
description='py.test and pylib: advanced testing tool and networking lib', description='py.test and pylib: advanced testing tool and networking lib',
long_description = long_description, long_description = long_description,
version= trunk or '1.0.0b9', version= trunk or '1.0.0',
url='http://pylib.org', url='http://pylib.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],