Is it possible to make a unittest decorator to rename a method from "x" to "testx?"

Ned Batchelder ned at nedbatchelder.com
Thu Aug 8 13:14:37 EDT 2013


On 8/8/13 12:17 PM, adam.preble at gmail.com wrote:
> On Thursday, August 8, 2013 3:50:47 AM UTC-5, Peter Otten wrote:
>> Peter Otten wrote:
>> Oops, that's an odd class name. Fixing the name clash in Types.__new__() is
>>
>> left as an exercise...
> I will do some experiments with a custom test loader since I wasn't aware of that as a viable alternative.  I am grateful for the responses.
If you can use another test runner, they often have more flexible and 
powerful ways to do everything.  nosetests will let you use a __test__ 
attribute, for example, to mark tests.  Your decorator could simply 
assign that attribute on the test methods.

You'd still write your tests using the unittest base classes, but run 
them with nose.

--Ned.



More information about the Python-list mailing list