Introducing unittest-fixtures
Briefly

unittest-fixtures enables declaring TestCase fixtures as standalone functions and applying them via decorators instead of modifying setUp(). Fixtures are passed to decorators and are instantiated when a test method runs, then attached to the test method via a fixtures keyword argument. Fixture functions always receive a Fixtures argument to allow inter-fixture dependencies. Fixture functions may define keyword parameters but those parameters must have defaults so tests can supply values via the decorator. The library supports duplicating a fixture under different names and ensures dependent fixtures share instances only when they reference the same fixture name.
unittest-fixtures spun off from my Gentoo Build Publisher project. I use unittest, the test framework in the Python standard library, where it's customary to define a TestCase's fixtures in the.setUp() method. Having done it this way for years, it occurred to me one day that this goes against OCP. What if instead of cracking open the.setUp() method to add a fixture to a TestCase one could instead add a decorator? That's what unittest-fixtures allows one to do.
In the above example, dog is a fixture function. Fixture functions are passed to the given decorator. When the test method is run, the fixtures are "instantiated" and attached to the fixtures keyword argument of the test method. Fixture functions are always passed a Fixtures argument. Because fixtures can depend on other fixtures. For example: Fixture functions can have keyword parameters, but those parameters must have defaults. Then one's TestCase can use the where decorator to passed the parameter:
Read at Lunarcowboy
[
|
]