[py-dev] using docstrings for test descriptions

holger krekel holger at merlinux.eu
Thu Jul 9 13:47:09 CEST 2009


On Wed, Jul 08, 2009 at 22:05 +0100, Frederik Dohr wrote:
>> Thanks, that looks promising.
>> Might take me a week or two to come up with something presentable
>
> I might have spoken too soon.
> After some naive hacking, I now have a simple proof of concept. In the  
> spirit of "release early, release often", here's the patch:

good idea :) 

>     http://gist.github.com/141977#LID1
> (also attached below)
> Plus some sample output:
>     http://gist.github.com/141977#LID49
>
> While this is certainly not release-ready, I'd appreciate feedback on  
> whether it's the right approach.

sure, here is some quick feedback.

a) Your change presumes that all test items are python test
   functions which is not true.  With 

      if isinstance(item, py.test.collect.Function) 

   you can check that you are dealing with python test
   functions. 

b) it's probably better to do the reporting tweak in 
   "def _reportinfoline" which deals with
   exactly presenting the verbose line. 

c) please add a test to the pytest_terminal.py file 
   and i recommend to rather copy+modify the "test_verbose" 
   one from py/test/testing/acceptance_test.py 
   you can simplify it of course to just test output
   for a single test function.  

best,
holger

>
>
> Index: py/test/plugin/pytest_terminal.py
> ===================================================================
> --- py/test/plugin/pytest_terminal.py	(revision 66152)
> +++ py/test/plugin/pytest_terminal.py	(working copy)
> @@ -284,6 +284,11 @@
>          except AttributeError:
>              pass
>          reportinfo = item.config.hook.pytest_report_iteminfo(item=item)
> +        # add docstring to message
> +        docstring = item.obj.__doc__ # TODO: shorten
> +        reportinfo = list(reportinfo) # mutable type req'd -- XXX: hacky
> +        reportinfo[-1] = "%s: %s" % (reportinfo[-1], docstring)
> +        reportinfo = tuple(reportinfo)
>          # cache on item
>          item.__reportinfo = reportinfo
>          return reportinfo
>

-- 
Metaprogramming, Python, Testing: http://tetamap.wordpress.com
Python, PyPy, pytest contracting: http://merlinux.eu 



More information about the Pytest-dev mailing list