nose-devs/nose — Issue #289: nose fails when importing * from unittest
Author: jpellerin
Created: 2011-12-14 16:06:36+00:00
State: open

What steps will reproduce the problem?
1. in a blank directory, create a "example_test.py" file containing only:
from unittest import *

2. run noesetests

What is the expected output? What do you see instead?

expected no tests to run, instead I get:
$ nosetests
E
======================================================================
Traceback (most recent call last):
File "/usr/bin/nosetests", line 9, in
load_entry_point('nose==1.0.0', 'console_scripts', 'nosetests')()
File "/usr/lib/python2.7/site-packages/nose/core.py", line 118, in __init__
**extra_args)
File "/usr/lib64/python2.7/unittest/main.py", line 95, in __init__
self.runTests()
File "/usr/lib/python2.7/site-packages/nose/core.py", line 197, in runTests
result = self.testRunner.run(self.test)
File "/usr/lib/python2.7/site-packages/nose/core.py", line 63, in run
result.printErrors()
File "/usr/lib/python2.7/site-packages/nose/result.py", line 103, in printErrors
_TextTestResult.printErrors(self)
File "/usr/lib64/python2.7/unittest/runner.py", line 108, in printErrors
self.printErrorList('ERROR', self.errors)
File "/usr/lib64/python2.7/unittest/runner.py", line 114, in printErrorList
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
File "/usr/lib/python2.7/site-packages/nose/result.py", line 82, in getDescription
return test.shortDescription() or str(test)
File "/usr/lib/python2.7/site-packages/nose/case.py", line 173, in shortDescription
if desc == str(self.test):
File "/usr/lib64/python2.7/unittest/case.py", line 1047, in __str__
self._testFunc.__name__)
AttributeError: 'str' object has no attribute '__name__'

What version of the product are you using? On what operating system?

$ nosetests --version
nosetests version 1.0.0
$ uname -r
2.6.38.6-27.fc15.x86_64

Please provide any additional information below.

Using nosetests -vv, I see the following snippet:

nose.selector: DEBUG: wantModule ? True
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantClass ? None
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantClass ? None
nose.selector: DEBUG: wantClass ? None
nose.selector: DEBUG: wantClass ? True
nose.selector: DEBUG: wantMethod >? None
nose.selector: DEBUG: wantMethod >? None
nose.selector: DEBUG: wantMethod >? None
nose.selector: DEBUG: wantMethod >? None
nose.selector: DEBUG: wantMethod >? None
nose.selector: DEBUG: wantMethod >? None
nose.suite: DEBUG: Create suite for []
nose.suite: DEBUG: tests [] context None
nose.suite: DEBUG: wrap []
File "/usr/lib64/python2.7/unittest/case.py", line 1047, in __str__
self._testFunc.__name__)
nose.suite: DEBUG: Context suite for [Test()] () (45807376)
nose.suite: DEBUG: get ancestry
nose.suite: DEBUG: ancestors ['test_example']
nose: DEBUG: __import__ test_example
nose: DEBUG: resolve: [], test_example, ,
nose.suite: DEBUG: suite has ancestor test_example

it seems that importing * from unittest brings in unittest's FunctionTestCase, which nose decides is a runnable test. And I guess it's being constructed with a string instead of a function.

Google Code Info:
Issue #: 422
Author: gfxm...@gmail.com
Created On: 2011-05-27T11:21:42.000Z
Closed On: 2011-05-27T15:09:24.000Z