Today, I found myself in a situation where I had a few different classes inheriting from each other, e.g.:
1 2 3 4 5 6 7 8 9 | |
Specifically, each of these classes was a test class that I was
running using nose – B and C had different setup methods than
A, but otherwise ran the same test. However, nosetests -v doesn’t
print out the name of the method’s class, only the docstring, which is
of course the same for all three classes. This made it very difficult
to tell which method was actually failing.
To resolve this, I wrote a metaclass to intercept each class at creation time and rewrite its docstrings to be prefixed with the name of the class. This was probabily overkill, but I’d been itching to play around with metaclasses for a while and decided this was a semi-valid excuse.