[py-dev] using docstrings for test descriptions

Frederik Dohr fdg001 at gmx.net
Wed Jul 8 23:05:30 CEST 2009


> 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:
     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.


Thanks,

Fred


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



More information about the Pytest-dev mailing list