Yelp/Testify — pull request #52 by blampe (2012-02-17 13:10:23+00:00)
Title: detect unittest.TestCases and allow fixture mixins

Lesson of the day: Testify code will boldly and unabashedly vomit Python magic all over your screen if you dare look at it.

This was difficult to implement due to the sheer amount of meta-WTF, so I've tried to thoroughly document my changes and the reasoning behind them. Normally I would never write anything like this because it's totally incomprehensible, but that was the status quo I was working with, so I can only hope that this is strictly less incomprehensible.

The high-level explanation goes thusly. Instead of traversing the class hierarchy to determine which fixtures are oldest, we just give them an increasing id every time they're declared. When we instantiate a test, we then collect all of the declared fixtures on the class and order them by their ids. This means a fixture can be declared on any object, and then be detected after being mixed into a `testify.TestCase`. To detect `unittest.TestCases`, we just keep an eye out for them and delicately construct a new `testify.TestCase` instance (and hierarchy) when we see them.

Logically separate changes, I know, but `unittest` detection came first -- and I quickly realized that was pretty much useless without more robust fixtures.

This was motivated by my need to use tornado's `unittest.TestCases`. I wanted to subclass `AsyncHTTPTestCase`, define some `@setup` stuff on it, and then have children inherit that class. This makes that possible. I've also run this on several yelp test modules and they appear unaffected.

Refs #28 and #51.