[TIP] Test discovery for unittest

Olemis Lang olemis at gmail.com
Mon Apr 13 06:23:43 PDT 2009

On Sat, Apr 11, 2009 at 9:14 AM, Robert Collins
<robertc at robertcollins.net> wrote:
> On Sat, 2009-04-11 at 15:29 +0300, Marius Gedminas wrote:
> For example, we have a VFS (which does http, https, sftp, ftp, file, bzr
> +ssh etc). In test_transport_implementations.py we have:
> def load_tests(standard_tests, module, loader):
>    """Multiply tests for tranport implementations."""
>    result = loader.suiteClass()
>    scenarios = transport_test_permutations()
>    return multiply_tests(standard_tests, scenarios, result)
> scenarios is an iterable of (label, attributes) tuples. E.g.
> [('sftp', {'transport_factory': SFTPTransportFactory}), ...]
> multiply_tests deep copies all the tests its given, renames the copies
> using the label so they are distinctive, and applies the attributes to
> the copies, adding the resulting tests to result - its a
> DependencyInjection pattern, for folk that like naming things :).

This is pretty similar to what I've done (about 5 | 4 years ago ) in
CASPy test suite but using decorators. In fact decorator pattern and
mixins are very similar (they solve the same problems), however the
former (dec-patt) is a more dynamic approach since it operates at the
object-level, while mixins do it at class-level (that's one of the
reasons why I dont like mixins :P)

Its good to know ...



Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

More information about the testing-in-python mailing list