diff --git a/CHANGELOG b/CHANGELOG index 35da2e74b..86b82aa82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,13 @@ Changes between 2.2.4 and 2.2.5.dev - fix issue159: improve http://pytest.org/latest/faq.html especially with respect to the "magic" history, also mention pytest-django, trial and unittest integration. +- reporting refinements: + - pytest_report_header now receives a "startdir" so that + you can use startdir.bestrelpath(yourpath) to show + nice relative path + - allow plugins to implement both pytest_report_header and + pytest_sessionstart (sessionstart is invoked first). + - don't show deselected reason line if there is none Changes between 2.2.3 and 2.2.4 ----------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 283f55cfe..9fae16cf3 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.2.5.dev2' +__version__ = '2.2.5.dev3' diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index b05e33421..ec98b0de3 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -193,7 +193,7 @@ def pytest_assertrepr_compare(config, op, left, right): # hooks for influencing reporting (invoked from _pytest_terminal) # ------------------------------------------------------------------------- -def pytest_report_header(config): +def pytest_report_header(config, startdir): """ return a string to be displayed as header info for terminal reporting.""" def pytest_report_teststatus(report): diff --git a/_pytest/main.py b/_pytest/main.py index b234d0a8e..f600ebe34 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -29,7 +29,6 @@ def pytest_addoption(parser): group._addoption('--maxfail', metavar="num", action="store", type="int", dest="maxfail", default=0, help="exit after first num failures or errors.") - group._addoption('--strict', action="store_true", help="run pytest in strict mode, warnings become errors.") diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 28d4fd99e..b825cc8bf 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -2,7 +2,8 @@ This is a good source for looking at the various reporting hooks. """ -import pytest, py +import pytest +import py import sys import os @@ -94,7 +95,7 @@ class TerminalReporter: self._numcollected = 0 self.stats = {} - self.curdir = py.path.local() + self.startdir = self.curdir = py.path.local() if file is None: file = py.std.sys.stdout self._tw = py.io.TerminalWriter(file) @@ -109,9 +110,9 @@ class TerminalReporter: def write_fspath_result(self, fspath, res): if fspath != self.currentfspath: self.currentfspath = fspath - #fspath = self.curdir.bestrelpath(fspath) + #fspath = self.startdir.bestrelpath(fspath) self._tw.line() - #relpath = self.curdir.bestrelpath(fspath) + #relpath = self.startdir.bestrelpath(fspath) self._tw.write(fspath + " ") self._tw.write(res) @@ -243,6 +244,7 @@ class TerminalReporter: def pytest_collection_modifyitems(self): self.report_collect(True) + @pytest.mark.trylast def pytest_sessionstart(self, session): self._sessionstarttime = py.std.time.time() if not self.showheader: @@ -258,7 +260,8 @@ class TerminalReporter: getattr(self.config.option, 'pastebin', None): msg += " -- " + str(sys.executable) self.write_line(msg) - lines = self.config.hook.pytest_report_header(config=self.config) + lines = self.config.hook.pytest_report_header( + config=self.config, startdir=self.startdir) lines.reverse() for line in flatten(lines): self.write_line(line) @@ -463,8 +466,9 @@ class TerminalReporter: m = self.config.option.markexpr if m: l.append("-m %r" % m) - self.write_sep("=", "%d tests deselected by %r" %( - len(self.stats['deselected']), " ".join(l)), bold=True) + if l: + self.write_sep("=", "%d tests deselected by %r" %( + len(self.stats['deselected']), " ".join(l)), bold=True) def repr_pythonversion(v=None): if v is None: diff --git a/setup.py b/setup.py index 01be0ca47..b86221881 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.2.5.dev2', + version='2.2.5.dev3', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 06532fe53..20942404c 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -632,17 +632,20 @@ class TestGenericReporting: def test_pytest_report_header(self, testdir, option): testdir.makeconftest(""" + def pytest_sessionstart(session): + session.config._somevalue = 42 def pytest_report_header(config): - return "hello: info" + return "hello: %s" % config._somevalue """) testdir.mkdir("a").join("conftest.py").write(""" -def pytest_report_header(config): - return ["line1", "line2"]""") +def pytest_report_header(config, startdir): + return ["line1", str(startdir)] +""") result = testdir.runpytest("a") result.stdout.fnmatch_lines([ "line1", - "line2", - "*hello: info*", + str(testdir.tmpdir), + "*hello: 42*", ]) @pytest.mark.xfail("not hasattr(os, 'dup')") diff --git a/tox.ini b/tox.ini index 60ea37c72..f0bf60855 100644 --- a/tox.ini +++ b/tox.ini @@ -72,7 +72,7 @@ commands= minversion=2.0 plugins=pytester #--pyargs --doctest-modules --ignore=.tox -addopts= -rxs +addopts= -rxs rsyncdirs=tox.ini pytest.py _pytest testing python_files=test_*.py *_test.py python_classes=Test Acceptance