TestCases and helpers¶
TestCases¶
Test classes in funq are subclasses of unittest.TestCase
.
-
class
funq.testcase.
BaseTestCase
(*args, **kwargs)[source]¶ Abstract class of a testcase for Funq.
It defines a common behaviour to name tests methods and uses the metaclass
MetaParameterized
that allows to generate methods from data.It inherits from
unittest.TestCase
, thus allowing to use very useful methods like assertEquals, assertFalse, etc.
-
class
funq.testcase.
FunqTestCase
(*args, **kwargs)[source]¶ A testcase to launch an application and write tests against it.
The class attribute __app_config_name__ is required and must contains the name of a section in the funq configuration file. A class attribute __app_config__ will then be automatically created to give access to the configuration of the application (
funq.client.ApplicationConfig
).Variables: funq – instance of funq.client.FunqClient
, allowing to manipulate the application.
-
class
funq.testcase.
MultiFunqTestCase
(*args, **kwargs)[source]¶ A testcase to launch multiple applications at the same time and write tests against them.
The class attribute __app_config_names__ is required and must contains a list of section’s names in the funq configuration file. A class attribute __app_configs__ will then be automatically created to give access to the configurations of the application (a dict with values of type
funq.client.ApplicationConfig
, where the keys are configuration names).Variables: funq – a dict that contains funq.client.FunqClient
, allowing to manipulate the application. Keys are configuration names.
Helpers¶
-
funq.testcase.
todo
(skip_message, exception_cls=<type 'exceptions.AssertionError'>)[source]¶ A decorator to skip a test on given exception types. If the decorated test pass, an exception
AssertionSuccessError
will be thrown.It is possible to specify which type of Exception is handled with the exception_cls argument.
Example:
class MyTestCase(FunqTestCase): __app_config_name__ = 'ma_conf' @todo("this test needs something to pass") def test_one(self): raise AssertionError('this will fail')
Parameters: - skip_message – error message when test is skipped
- exception_cls – Exception type or tuple of Exception type that are handled to skip a test.
-
funq.testcase.
parameterized
(func_suffix, *args, **kwargs)[source]¶ A decorator that can generate methods given a base method and some data.
func_suffix is used as a suffix for the new created method and must be unique given a base method. if func_suffix countains characters that are not allowed in normal python function name, these characters will be replaced with “_”.
This decorator can be used more than once on a single base method. The class must have a metaclass of
MetaParameterized
.Example:
# This example will generate two methods: # # - MyTestCase.test_it_1 # - MyTestCase.test_it_2 # class MyTestCase(FunqTestCase): __app_config_name__ = 'ma_conf' @parameterized("1", 5, named='nom') @parameterized("2", 6, named='nom2') def test_it(self, value, named=None): print value, named
Parameters: - func_suffix – will be used as a suffix for the new method
- *args – arguments to pass to the new method
- **kwargs – named arguments to pass to the new method
-
funq.testcase.
with_parameters
(parameters)[source]¶ A decorator that can generate methods given a base method and some data. Acts like
parameterized()
, but define all methods in one call.Example:
# This example will generate two methods: # # - MyTestCase.test_it_1 # - MyTestCase.test_it_2 # DATA = [("1", [5], {'named':'nom'}), ("2", [6], {'named':'nom2'})] class MyTestCase(FunqTestCase): app_config_name = 'ma_conf' @with_parameters(DATA) def test_it(self, value, named=None): print value, named
Parameters: parameters – list of tuples (func_suffix, args, kwargs) defining parameters like in todo()
.
-
class
funq.testcase.
MetaParameterized
[source]¶ A metaclass that allow a class to use decorators like
parameterized()
orwith_parameters()
to generate new methods.