Open GoogleCodeExporter opened 8 years ago
This 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, )
Original comment by dsdal...@gmail.com
on 7 Mar 2009 at 4:05
For a few other ways to work around this issue see this post:
http://achinghead.com/archive/85/nosetests-generators-descriptions/
Original comment by way...@gmail.com
on 12 Jun 2009 at 8:03
Actually 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,
Original comment by ffxvzero@gmail.com
on 24 Feb 2011 at 5:58
Attachments:
Another 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 <lambda>)
Original comment by miller...@gmail.com
on 12 Apr 2012 at 9:50
Original issue reported on code.google.com by
dsdal...@gmail.com
on 7 Mar 2009 at 3:53