1 new changeset in pytest:

http://bitbucket.org/hpk42/pytest/changeset/81a1105d2fee/
changeset:   r2139:81a1105d2fee
user:        hpk
date:        2011-01-12 19:39:36
summary:     fix issue12 - show plugin versions with "--version" and 
"--traceconfig" and also document how to add extra information to reporting 
test header
affected #:  9 files (3.1 KB)

--- a/CHANGELOG Wed Jan 12 19:17:54 2011 +0100
+++ b/CHANGELOG Wed Jan 12 19:39:36 2011 +0100
@@ -1,5 +1,8 @@
 Changes between 2.0.0 and 2.0.1.devX
 ----------------------------------------------
+- fix issue12 - show plugin versions with "--version" and
+  "--traceconfig" and also document how to add extra information 
+  to reporting test header
 - fix issue17 (import-* reporting issue on python3) by
   requiring py>1.4.0 (1.4.1 is going to include it)
 - fix issue10 (numpy arrays truth checking) by refining


--- a/_pytest/core.py   Wed Jan 12 19:17:54 2011 +0100
+++ b/_pytest/core.py   Wed Jan 12 19:39:36 2011 +0100
@@ -63,6 +63,7 @@
         self._plugins = []
         self._hints = []
         self.trace = TagTracer().get("pluginmanage")
+        self._plugin_distinfo = []
         if os.environ.get('PYTEST_DEBUG'):
             err = sys.stderr
             encoding = getattr(err, 'encoding', 'utf8')
@@ -156,6 +157,7 @@
                 plugin = ep.load()
             except DistributionNotFound:
                 continue
+            self._plugin_distinfo.append((ep.dist, plugin))
             self.register(plugin, name=name)
 
     def consider_preparse(self, args):


--- a/_pytest/helpconfig.py     Wed Jan 12 19:17:54 2011 +0100
+++ b/_pytest/helpconfig.py     Wed Jan 12 19:39:36 2011 +0100
@@ -28,6 +28,10 @@
         p = py.path.local(pytest.__file__)
         sys.stderr.write("This is py.test version %s, imported from %s\n" %
             (pytest.__version__, p))
+        plugininfo = getpluginversioninfo(config)
+        if plugininfo:
+            for line in plugininfo:
+                sys.stderr.write(line + "\n")
         return 0
     elif config.option.help:
         config.pluginmanager.do_configure(config)
@@ -69,11 +73,26 @@
     ('pytest_plugins', 'list of plugin names to load'),
 ]
 
+def getpluginversioninfo(config):
+    lines = []
+    plugininfo = config.pluginmanager._plugin_distinfo
+    if plugininfo:
+        lines.append("setuptools registered plugins:")
+        for dist, plugin in plugininfo:
+            loc = getattr(plugin, '__file__', repr(plugin))
+            content = "%s-%s at %s" % (dist.project_name, dist.version, loc)
+            lines.append("  " + content)
+    return lines
+
 def pytest_report_header(config):
     lines = []
     if config.option.debug or config.option.traceconfig:
         lines.append("using: pytest-%s pylib-%s" %
             (pytest.__version__,py.__version__))
+
+        verinfo = getpluginversioninfo(config)
+        if verinfo:
+            lines.extend(verinfo)
             
     if config.option.traceconfig:
         lines.append("active plugins:")


--- a/doc/example/simple.txt    Wed Jan 12 19:17:54 2011 +0100
+++ b/doc/example/simple.txt    Wed Jan 12 19:39:36 2011 +0100
@@ -138,7 +138,7 @@
     E       assert 4 < 4
     
     test_compute.py:3: AssertionError
-    1 failed, 4 passed in 0.02 seconds
+    1 failed, 4 passed in 0.03 seconds
 
 As expected when running the full range of ``param1`` values
 we'll get an error on the last one.
@@ -167,13 +167,13 @@
 
     $ py.test
     =========================== test session starts 
============================
-    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev3
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8
     gw0 I / gw1 I / gw2 I / gw3 I
     gw0 [0] / gw1 [0] / gw2 [0] / gw3 [0]
     
     scheduling tests via LoadScheduling
     
-    =============================  in 0.29 seconds 
=============================
+    =============================  in 0.43 seconds 
=============================
 
 .. _`retrieved by hooks as item keywords`:
 
@@ -214,12 +214,12 @@
 
     $ py.test -rs    # "-rs" means report details on the little 's'
     =========================== test session starts 
============================
-    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev3
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8
     collecting ... collected 2 items
     
     test_module.py .s
     ========================= short test summary info 
==========================
-    SKIP [1] /tmp/doc-exec-25/conftest.py:9: need --runslow option to run
+    SKIP [1] /tmp/doc-exec-46/conftest.py:9: need --runslow option to run
     
     =================== 1 passed, 1 skipped in 0.02 seconds 
====================
 
@@ -227,7 +227,7 @@
 
     $ py.test --runslow
     =========================== test session starts 
============================
-    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev3
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8
     collecting ... collected 2 items
     
     test_module.py ..
@@ -303,3 +303,57 @@
 to rather use your own application module rather than ``sys``
 for handling flag.
 
+Adding info to test report header
+--------------------------------------------------------------
+
+.. regendoc:wipe
+
+It's easy to present extra information in a py.test run::
+
+    # content of conftest.py
+    
+    def pytest_report_header(config):
+        return "project deps: mylib-1.1"
+
+which will add the string to the test header accordingly::
+
+    $ py.test
+    =========================== test session starts 
============================
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8
+    project deps: mylib-1.1
+    collecting ... collected 0 items
+    
+    =============================  in 0.00 seconds 
=============================
+
+.. regendoc:wipe
+
+You can also return a list of strings which will be considered as several
+lines of information.  You can of course also make the amount of reporting
+information on e.g. the value of ``config.option.verbose`` so that
+you present more information appropriately::
+
+    # content of conftest.py
+    
+    def pytest_report_header(config):
+        if config.option.verbose > 0:
+            return ["info1: did you know that ...", "did you?"]
+
+which will add info only when run with "--v"::
+
+    $ py.test -v
+    =========================== test session starts 
============================
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8 -- 
/home/hpk/venv/0/bin/python
+    info1: did you know that ...
+    did you?
+    collecting ... collected 0 items
+    
+    =============================  in 0.00 seconds 
=============================
+
+and nothing when run plainly::
+
+    $ py.test
+    =========================== test session starts 
============================
+    platform linux2 -- Python 2.6.5 -- pytest-2.0.1.dev8
+    collecting ... collected 0 items
+    
+    =============================  in 0.00 seconds 
=============================


--- a/pytest.py Wed Jan 12 19:17:54 2011 +0100
+++ b/pytest.py Wed Jan 12 19:39:36 2011 +0100
@@ -1,7 +1,7 @@
 """
 unit and functional testing with Python.
 """
-__version__ = '2.0.1.dev7'
+__version__ = '2.0.1.dev8'
 __all__ = ['main']
 
 from _pytest.core import main, UsageError, _preloadplugins


--- a/setup.py  Wed Jan 12 19:17:54 2011 +0100
+++ b/setup.py  Wed Jan 12 19:39:36 2011 +0100
@@ -22,7 +22,7 @@
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.0.1.dev7',
+        version='2.0.1.dev8',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


--- a/testing/test_config.py    Wed Jan 12 19:17:54 2011 +0100
+++ b/testing/test_config.py    Wed Jan 12 19:39:36 2011 +0100
@@ -231,6 +231,8 @@
         assert name == "pytest11"
         class EntryPoint:
             name = "mytestplugin"
+            class dist:
+                pass
             def load(self):
                 class PseudoPlugin:
                     x = 42


--- a/testing/test_core.py      Wed Jan 12 19:17:54 2011 +0100
+++ b/testing/test_core.py      Wed Jan 12 19:39:36 2011 +0100
@@ -66,6 +66,7 @@
             assert name == "pytest11"
             class EntryPoint:
                 name = "pytest_mytestplugin"
+                dist = None
                 def load(self):
                     class PseudoPlugin:
                         x = 42


--- a/testing/test_helpconfig.py        Wed Jan 12 19:17:54 2011 +0100
+++ b/testing/test_helpconfig.py        Wed Jan 12 19:39:36 2011 +0100
@@ -1,13 +1,18 @@
 import py, pytest,os
 from _pytest.helpconfig import collectattr
 
-def test_version(testdir):
+def test_version(testdir, pytestconfig):
     result = testdir.runpytest("--version")
     assert result.ret == 0
     #p = py.path.local(py.__file__).dirpath()
     result.stderr.fnmatch_lines([
         '*py.test*%s*imported from*' % (pytest.__version__, )
     ])
+    if pytestconfig.pluginmanager._plugin_distinfo:
+        result.stderr.fnmatch_lines([
+            "*setuptools registered plugins:",
+            "*at*",
+        ])
 
 def test_help(testdir):
     result = testdir.runpytest("--help")
@@ -51,3 +56,9 @@
     result = testdir.runpytest()
     assert result.ret == 0
 
+def test_traceconfig(testdir):
+    result = testdir.runpytest("--traceconfig")
+    result.stdout.fnmatch_lines([
+        "*using*pytest*py*",
+        "*active plugins*",
+    ])

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.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to