[TIP] How to parameterize a fixture based on a parser option with py.test?

Wouter Overmeire lodagro at gmail.com
Fri Dec 13 03:21:38 PST 2013


Hi,

Using py.test (version 2.5.0) i would like to run a number of test on a
user select-able platform with multiple configurations.  A platform is a
bunch measurement instruments, and  hardware under test. The tests are not
aware on which specific platform they run, nor how the platform is
configured, they get a platform fixture object and do stuff with it.

Using two parser arguments "--platform" and  "--config"" the user can
select a platform and a platform config. The platform fixture function gets
the options from the request object, creates, configures and returns the
platform. So far so good.

However, test need to run for many configs (range 100) on  a single
platform, configs are grouped in sets. The user should be able to select
the config set. Instead of selecting a single config i would like to select
a set, the ""--config" option is now the name (string) referring to a
factory function generating a list of configs. But i`m stuck on how to
parameterize the platform fixture function using the "--config" parser
option. The fixture decorator has a "parameters" argument to parameterize a
fixture, which can do the trick for a hardcoded config set, but how to set
the values based on a parser option? I also tried to use
pytest.yield_fixture, but this supports only a single yield statement :-(.

Any ideas?

Thanks,

Wouter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20131213/a6d28a12/attachment.html>


More information about the testing-in-python mailing list