hRobert12 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

test generators description attribute not cached for failed tests #244

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by dsdal...@gmail.com on 7 Mar 2009 at 3:53

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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:

GoogleCodeExporter commented 8 years ago
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