next generation "generative tests"

Create issue
Issue #2 resolved
Holger Krekel repo owner created an issue

py.test and nose both provide so called "generative" tests by using the "yield" statement. However, the benefits over just doing a loop are limited. also it complicates test collection and reporting. With the new "funcargs" a new approach becomes feasible. The basic idea is to write normal test functions that receive a function argument like they can with 1.0 but call those test functions multiple times with different values.

one application of this idea i discussed with Samuele Pedroni who works on a plugin for running javascript-unittests from py.test. Over a few iterations we finally arrived at a rough sketch for how a plugin could run a test function multiple times depending on available/specified browser instances:

{{{ #!python

class OejskitPlugin: # hook called for each collected test function def pytest_pycollect_genfunction(self, function): if not function.hasfuncarg("browser"): return l = [] for browser in self.getbrowsers(): # let's fish for a function object attribute for fun browseronly = getattr(function.obj, 'browseronly', []) if not browseronly or in browseronly: l.append({'browser': browser}) return l }}}

Comments (10)

  1. Holger Krekel reporter

    merging the new function generators, addresses issue 2 - introduce a new pytest_genfuncruns hook for generating tests with multiple funcargs - new and extended docs: doc/test/funcargs.txt - factor all funcargs related code into py/test/ - remove request.maketempdir call (you can use request.config.mktemp)


  2. Holger Krekel reporter
    • changed status to new

    resolved since b3 release - now there is pytest_generate_tests hook. turns out that Samuele needed something else for his browser test integration, though.

  3. Log in to comment