[TIP] Reusable test suites in nose
Michael Williamson
mike at zwobble.org
Mon Jan 7 03:58:05 PST 2013
Hello,
When writing different implementations of the same interface, it's
useful to be able to run the same test suite against each different
implementation. I've quickly knocked up a bit of code to do just that
with nose -- is there something similar that already exists elsewhere?
The way it works is:
There's a class called TestSuiteBuilder, which collects up all the
tests:
https://github.com/mwilliamson/peachtree/blob/7724d6176cdc574208c771fec6d75ff736259d48/tests/suite_builder.py
You then define your tests, which accept some number of arguments. The
idea is that the exact implementation of those arguments is what will
vary. In this case, I'm testing a general interface for a virtual
machine provider.
https://github.com/mwilliamson/peachtree/blob/7724d6176cdc574208c771fec6d75ff736259d48/tests/provider_tests.py
Then, you instantiate a test class with a specific implementation using
the "create" method:
https://github.com/mwilliamson/peachtree/blob/7724d6176cdc574208c771fec6d75ff736259d48/tests/qemu_tests.py
Michael
More information about the testing-in-python
mailing list