[py-svn] commit/pytest: hpk42: some refinements to reporting and hook order

Bitbucket commits-noreply at bitbucket.org
Thu Jun 21 11:07:39 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/6b8f9ccbaa28/
changeset:   6b8f9ccbaa28
user:        hpk42
date:        2012-06-21 11:07:22
summary:     some refinements to reporting and hook order
affected #:  8 files

diff -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,13 @@
 - 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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.2.5.dev2'
+__version__ = '2.2.5.dev3'


diff -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 _pytest/hookspec.py
--- a/_pytest/hookspec.py
+++ b/_pytest/hookspec.py
@@ -193,7 +193,7 @@
 # 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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 _pytest/main.py
--- a/_pytest/main.py
+++ b/_pytest/main.py
@@ -29,7 +29,6 @@
     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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 _pytest/terminal.py
--- 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 @@
         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 @@
     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 @@
     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 @@
            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 @@
             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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 setup.py
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@
         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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 testing/test_terminal.py
--- a/testing/test_terminal.py
+++ b/testing/test_terminal.py
@@ -632,17 +632,20 @@
 
     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 -r 10adfe5e262e33cc45dbf356daf1dfb5050e73d8 -r 6b8f9ccbaa284ea7d466d9b2fab4a5bf81872876 tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -72,7 +72,7 @@
 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

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list