z3c.recipe.compattest passes options to zope.testing's testrunner

View: New views
1 Messages — Rating Filter:   Alert me  

z3c.recipe.compattest passes options to zope.testing's testrunner

by Jonathan Ballet-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I made a patch for z3c.recipe.compattest which allows to specify
options which will be passed to zc.recipe.testrunner in order to
customize the runner behavior.

Our main use cases were:

* passing defaults options to zope.testing.testrunner.run(). I like to
have color by default, stop on first error and verbose tests by
default
* we needed to pass to some test values from the environment, using
the 'environment' option of z3c.recipe.testrunner

I made this feature "extensible", so that you don't have to update
this recipe each time the used runner has a new useful option (every
options prefixed by 'runner-' are passed to the test runner) and that
it isn't bound to a particular testrunner (I'm not sure this is a goal
of z3c.recipe.compattest, but it well).

Cheers,

 Jonathan

[option-to-runners.patch]

Options can now be passed to generated test runners

diff -r 61275f192e6e CHANGES.txt
--- a/CHANGES.txt Mon Sep 14 15:02:34 2009 +0000
+++ b/CHANGES.txt Tue Sep 22 13:29:14 2009 +0200
@@ -5,7 +5,8 @@
 0.10 (unreleased)
 =================
 
-- Nothing changed yet.
+- Options prefixed by ``runner-`` are automatically passed to generated test
+  runners.
 
 
 0.9 (2009-09-14)
diff -r 61275f192e6e src/z3c/recipe/compattest/README.txt
--- a/src/z3c/recipe/compattest/README.txt Mon Sep 14 15:02:34 2009 +0000
+++ b/src/z3c/recipe/compattest/README.txt Tue Sep 22 13:29:14 2009 +0200
@@ -109,3 +109,28 @@
 
 >>> ls('develop-eggs')
 - z3c.recipe.compattest.egg-link
+
+Passing options to the test runners
+===================================
+
+If you want to use custom options in the generated test runners, you can specify
+them in the part options, prefixed by ``runner-``. That is, if you want to pass
+the ``--foo`` option by default to all generated test runners, you can set
+``runner-defaults = ['--foo']`` in your part:
+
+>>> write('buildout.cfg', """
+... [buildout]
+... parts = compattest
+...
+... [compattest]
+... recipe = z3c.recipe.compattest
+... include = z3c.recipe.compattest
+... runner-defaults = ['-c', '-v', '-v']
+... """)
+>>> ignore = system(buildout)
+>>> cat('bin', 'compattest-z3c.recipe.compattest')
+#!...python...
+...run(...['-c', '-v', '-v']...
+
+Every options prefixed by ``runner-`` will be automatically passed to the
+generated test runners.
diff -r 61275f192e6e src/z3c/recipe/compattest/recipe.py
--- a/src/z3c/recipe/compattest/recipe.py Mon Sep 14 15:02:34 2009 +0000
+++ b/src/z3c/recipe/compattest/recipe.py Tue Sep 22 13:29:14 2009 +0200
@@ -12,6 +12,8 @@
     return [item.strip() for item in result]
 
 
+RUNNER_PREFIX = 'runner-'
+
 class Recipe(object):
 
     def __init__(self, buildout, name, options):
@@ -35,6 +37,14 @@
             'svn_directory', os.path.join(
             self.buildout['buildout']['parts-directory'], self.name))
 
+        # Gather options to be passed to the underlying testrunner.
+        # They should all be prefixed by RUNNER_PREFIX.
+        self.testrunner_options = {}
+        for opt in self.options:
+            if opt.startswith(RUNNER_PREFIX):
+                runner_opt = opt[len(RUNNER_PREFIX):]
+                self.testrunner_options[runner_opt] = self.options[opt]
+
     def install(self):
         if self.svn_url:
             if not os.path.exists(self.svn_directory):
@@ -72,7 +82,10 @@
                     self.wanted_packages.remove(package)
                     continue
                 raise
-            options = dict(eggs=package + extras)
+
+            options = self.testrunner_options.copy()
+            options['eggs'] = package + extras
+
             recipe = zc.recipe.testrunner.TestRunner(
                 self.buildout, '%s-%s' % (self.name, package), options)
             installed.extend(recipe.install())


_______________________________________________
Grok-dev mailing list
Grok-dev@...
https://mail.zope.org/mailman/listinfo/grok-dev