Workaround for generated descriptions of the nosetests

2011-09-20

It's a known problem [1], [2] that descriptions of the generated nosetests are not displayed properly in the detailed report on failures. The last .description attribute of the test function is used to describe all the failures.

My current workaround is to delattr the .description attribute just after the yield:

def check(a,b):
    "Description to be used in the detailed report on failures."
    assert a == b

def test_generator():
    for x,y in [(1,2), (1,1)]:
        # Description to be used in the run log.
        check.description = 'Pair: ' + str(x) + ", " + str(y)
        yield check, x, y
        delattr(check, "description")

Run results:

$ nosetests -v nosedesc.py
Pair: 1, 2 ... FAIL
Pair: 1, 1 ... ok

======================================================================
FAIL: nosedesc.test_generator(1, 2)
----------------------------------------------------------------------
Traceback (most recent call last):
(... censored ...)

As you see, the test description before the traceback is correct, it is not the last one used ("Pair: 1, 1").