
python-nose - issue #244
test generators description attribute not cached for failed tests
What steps will reproduce the problem?
from nose.tools import *
def check(a,b): assert_equal(a,b)
def test_generator(): check.description = 'test_fails' yield check, 1, 2
check.description = 'test_passes'
yield check, 1, 1
save as test.py in ./, run nosetests
What is the expected output? What do you see instead?
I would like to see:
$ nosetests
F.
FAIL: test_fails
instead I see:
$ nosetests
F.
FAIL: test_passes
What version of the product are you using? On what operating system?
10.4 on kubuntu intrepid
Please provide any additional information below.
Thank you for a very useful unit testing package. The test generators are very helpful, but there is a small problem in that the failure report does not list the function.description from the time of the failure, but rather the last description that was registered during execution.
Comment #1
Posted on Mar 7, 2009 by Happy KangarooThis is a useful workaround:
from nose.tools import * from functools import partial
import copy
def check(a,b): assert_equal(a,b)
def test_generator(): f = partial(check, 1, 2) f.description = 'test_fails' yield (f, )
f = partial(check, 1, 1)
f.description = 'test_passes'
yield (f, )
Comment #2
Posted on Jun 12, 2009 by Happy HorseFor a few other ways to work around this issue see this post:
http://achinghead.com/archive/85/nosetests-generators-descriptions/
Comment #3
Posted on Feb 24, 2011 by Grumpy RhinoActually this doesn't work when using the multiprocess plugin because the function re-loaded in the new process is actually 'partial' without the arguments, so nothing is called.
As #2 pointed, there is an alternative that uses classes, but this also suffers from problems when used with multiprocess. The reason is because the default makeTests function recognizes it is a 'class' and tries to load all its methods, even though the class is callable.
In order to circumvent this, it would be great if python nose recognized callable classes and treated that as functions instead of trying to load their methods (not sure if there are any compatibility issues here).
I am attaching a very short plugin called CallableClass that does this. It is enabled with --with-callableclass.
rosen diankov,
- callableclass.py 924
Comment #4
Posted on Apr 12, 2012 by Happy WombatAnother workaround would be to use a lambda wrapper. It's pretty much the same as the class method defined in comment 2.
from nose.tools import assert_equal
def get_check(desc): func = lambda a,b: assert_equal(a,b) func.description = desc return func
def test_generator(): yield get_check('test_fails'), 1, 2 yield get_check('test_passes'), 1, 1
Doesn't seem to work with multiprocess either though - I get: ERROR: Failure: ValueError (No such test )
Status: New