Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test generators description attribute not cached for failed tests #10

Open
jpellerin opened this issue Dec 14, 2011 · 3 comments
Open
Assignees

Comments

@jpellerin
Copy link
Member

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.

Google Code Info:
Issue #: 244
Author: [email protected]
Created On: 2009-03-07T15:53:40.000Z
Closed On:

@jpellerin
Copy link
Member Author

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, )

Google Code Info:
Author: [email protected]
Created On: 2009-03-07T16:05:34.000Z

@jpellerin
Copy link
Member Author

For a few other ways to work around this issue see this post:

http://achinghead.com/archive/85/nosetests-generators-descriptions/

Google Code Info:
Author: [email protected]
Created On: 2009-06-12T20:03:53.000Z

@ghost ghost assigned jpellerin Dec 14, 2011
@jpellerin
Copy link
Member Author

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,

Google Code Info:
Author: [email protected]
Created On: 2011-02-24T05:58:11.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant