some refinements to reporting and hook order
This commit is contained in:
parent
18306a4644
commit
ccc04b9fc4
|
@ -10,6 +10,13 @@ Changes between 2.2.4 and 2.2.5.dev
|
||||||
- fix issue159: improve http://pytest.org/latest/faq.html
|
- fix issue159: improve http://pytest.org/latest/faq.html
|
||||||
especially with respect to the "magic" history, also mention
|
especially with respect to the "magic" history, also mention
|
||||||
pytest-django, trial and unittest integration.
|
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
|
Changes between 2.2.3 and 2.2.4
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.2.5.dev2'
|
__version__ = '2.2.5.dev3'
|
||||||
|
|
|
@ -193,7 +193,7 @@ def pytest_assertrepr_compare(config, op, left, right):
|
||||||
# hooks for influencing reporting (invoked from _pytest_terminal)
|
# 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."""
|
""" return a string to be displayed as header info for terminal reporting."""
|
||||||
|
|
||||||
def pytest_report_teststatus(report):
|
def pytest_report_teststatus(report):
|
||||||
|
|
|
@ -29,7 +29,6 @@ def pytest_addoption(parser):
|
||||||
group._addoption('--maxfail', metavar="num",
|
group._addoption('--maxfail', metavar="num",
|
||||||
action="store", type="int", dest="maxfail", default=0,
|
action="store", type="int", dest="maxfail", default=0,
|
||||||
help="exit after first num failures or errors.")
|
help="exit after first num failures or errors.")
|
||||||
|
|
||||||
group._addoption('--strict', action="store_true",
|
group._addoption('--strict', action="store_true",
|
||||||
help="run pytest in strict mode, warnings become errors.")
|
help="run pytest in strict mode, warnings become errors.")
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
This is a good source for looking at the various reporting hooks.
|
This is a good source for looking at the various reporting hooks.
|
||||||
"""
|
"""
|
||||||
import pytest, py
|
import pytest
|
||||||
|
import py
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ class TerminalReporter:
|
||||||
self._numcollected = 0
|
self._numcollected = 0
|
||||||
|
|
||||||
self.stats = {}
|
self.stats = {}
|
||||||
self.curdir = py.path.local()
|
self.startdir = self.curdir = py.path.local()
|
||||||
if file is None:
|
if file is None:
|
||||||
file = py.std.sys.stdout
|
file = py.std.sys.stdout
|
||||||
self._tw = py.io.TerminalWriter(file)
|
self._tw = py.io.TerminalWriter(file)
|
||||||
|
@ -109,9 +110,9 @@ class TerminalReporter:
|
||||||
def write_fspath_result(self, fspath, res):
|
def write_fspath_result(self, fspath, res):
|
||||||
if fspath != self.currentfspath:
|
if fspath != self.currentfspath:
|
||||||
self.currentfspath = fspath
|
self.currentfspath = fspath
|
||||||
#fspath = self.curdir.bestrelpath(fspath)
|
#fspath = self.startdir.bestrelpath(fspath)
|
||||||
self._tw.line()
|
self._tw.line()
|
||||||
#relpath = self.curdir.bestrelpath(fspath)
|
#relpath = self.startdir.bestrelpath(fspath)
|
||||||
self._tw.write(fspath + " ")
|
self._tw.write(fspath + " ")
|
||||||
self._tw.write(res)
|
self._tw.write(res)
|
||||||
|
|
||||||
|
@ -243,6 +244,7 @@ class TerminalReporter:
|
||||||
def pytest_collection_modifyitems(self):
|
def pytest_collection_modifyitems(self):
|
||||||
self.report_collect(True)
|
self.report_collect(True)
|
||||||
|
|
||||||
|
@pytest.mark.trylast
|
||||||
def pytest_sessionstart(self, session):
|
def pytest_sessionstart(self, session):
|
||||||
self._sessionstarttime = py.std.time.time()
|
self._sessionstarttime = py.std.time.time()
|
||||||
if not self.showheader:
|
if not self.showheader:
|
||||||
|
@ -258,7 +260,8 @@ class TerminalReporter:
|
||||||
getattr(self.config.option, 'pastebin', None):
|
getattr(self.config.option, 'pastebin', None):
|
||||||
msg += " -- " + str(sys.executable)
|
msg += " -- " + str(sys.executable)
|
||||||
self.write_line(msg)
|
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()
|
lines.reverse()
|
||||||
for line in flatten(lines):
|
for line in flatten(lines):
|
||||||
self.write_line(line)
|
self.write_line(line)
|
||||||
|
@ -463,8 +466,9 @@ class TerminalReporter:
|
||||||
m = self.config.option.markexpr
|
m = self.config.option.markexpr
|
||||||
if m:
|
if m:
|
||||||
l.append("-m %r" % m)
|
l.append("-m %r" % m)
|
||||||
self.write_sep("=", "%d tests deselected by %r" %(
|
if l:
|
||||||
len(self.stats['deselected']), " ".join(l)), bold=True)
|
self.write_sep("=", "%d tests deselected by %r" %(
|
||||||
|
len(self.stats['deselected']), " ".join(l)), bold=True)
|
||||||
|
|
||||||
def repr_pythonversion(v=None):
|
def repr_pythonversion(v=None):
|
||||||
if v is None:
|
if v is None:
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.2.5.dev2',
|
version='2.2.5.dev3',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
|
@ -632,17 +632,20 @@ class TestGenericReporting:
|
||||||
|
|
||||||
def test_pytest_report_header(self, testdir, option):
|
def test_pytest_report_header(self, testdir, option):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
|
def pytest_sessionstart(session):
|
||||||
|
session.config._somevalue = 42
|
||||||
def pytest_report_header(config):
|
def pytest_report_header(config):
|
||||||
return "hello: info"
|
return "hello: %s" % config._somevalue
|
||||||
""")
|
""")
|
||||||
testdir.mkdir("a").join("conftest.py").write("""
|
testdir.mkdir("a").join("conftest.py").write("""
|
||||||
def pytest_report_header(config):
|
def pytest_report_header(config, startdir):
|
||||||
return ["line1", "line2"]""")
|
return ["line1", str(startdir)]
|
||||||
|
""")
|
||||||
result = testdir.runpytest("a")
|
result = testdir.runpytest("a")
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"line1",
|
"line1",
|
||||||
"line2",
|
str(testdir.tmpdir),
|
||||||
"*hello: info*",
|
"*hello: 42*",
|
||||||
])
|
])
|
||||||
|
|
||||||
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
||||||
|
|
Loading…
Reference in New Issue