2
2
# dependency injection ('scenarios') by tests.
4
4
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5
# Copyright (c) 2010 Martin Pool <mbp@sourcefrog.net>
5
# Copyright (c) 2010, 2011 Martin Pool <mbp@sourcefrog.net>
7
7
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
8
8
# license at the users choice. A copy of both licenses are available in the
129
130
scenario_parameters.update(parameter)
130
131
result.append((scenario_name, scenario_parameters))
135
def per_module_scenarios(attribute_name, modules):
136
"""Generate scenarios for available implementation modules.
138
This is typically used when there is a subsystem implemented, for
139
example, in both Python and C, and we want to apply the same tests to
140
both, but the C module may sometimes not be available.
142
Note: if the module can't be loaded, the sys.exc_info() tuple for the
143
exception raised during import of the module is used instead of the module
144
object. A common idiom is to check in setUp for that and raise a skip or
145
error for that case. No special helpers are supplied in testscenarios as
148
:param attribute_name: A name to be set in the scenario parameter
149
dictionary (and thence onto the test instance) pointing to the
150
implementation module (or import exception) for this scenario.
152
:param modules: An iterable of (short_name, module_name), where
153
the short name is something like 'python' to put in the
154
scenario name, and the long name is a fully-qualified Python module
158
for short_name, module_name in modules:
160
mod = __import__(module_name, {}, {}, [''])
165
{attribute_name: mod}))