pombreda / python-nose

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

nose fails when importing * from unittest #422

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 <module>
    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 <module 'test_example' from 
'/tmp/test_example.pyc'>? True
nose.selector: DEBUG: wantClass <class 'unittest.case.FunctionTestCase'>? True
nose.selector: DEBUG: wantClass <class 'unittest.case.SkipTest'>? None
nose.selector: DEBUG: wantClass <class 'unittest.case.TestCase'>? True
nose.selector: DEBUG: wantClass <class 'unittest.loader.TestLoader'>? True
nose.selector: DEBUG: wantClass <class 'unittest.result.TestResult'>? True
nose.selector: DEBUG: wantClass <class 'unittest.suite.TestSuite'>? True
nose.selector: DEBUG: wantClass <class 'unittest.runner.TextTestResult'>? None
nose.selector: DEBUG: wantClass <class 'unittest.runner.TextTestRunner'>? None
nose.selector: DEBUG: wantClass <class 'unittest.main.TestProgram'>? True
nose.selector: DEBUG: wantMethod <bound method type.setUpClass of <class 
'test_example.FunctionTestCase'>>? None
nose.selector: DEBUG: wantMethod <bound method type.tearDownClass of <class 
'test_example.FunctionTestCase'>>? None
nose.selector: DEBUG: wantMethod <bound method type.setUpClass of <class 
'unittest.case.FunctionTestCase'>>? None
nose.selector: DEBUG: wantMethod <bound method type.tearDownClass of <class 
'unittest.case.FunctionTestCase'>>? None
nose.selector: DEBUG: wantMethod <bound method type.setUpClass of <class 
'unittest.case.TestCase'>>? None
nose.selector: DEBUG: wantMethod <bound method type.tearDownClass of <class 
'unittest.case.TestCase'>>? None
nose.suite: DEBUG: Create suite for [<test_example.FunctionTestCase 
tec=runTest>]
nose.suite: DEBUG: tests [<test_example.FunctionTestCase tec=runTest>] context 
None
nose.suite: DEBUG: wrap [<test_example.FunctionTestCase tec=runTest>]
  File "/usr/lib64/python2.7/unittest/case.py", line 1047, in __str__
    self._testFunc.__name__)
nose.suite: DEBUG: Context suite for [Test(<test_example.FunctionTestCase 
tec=runTest>)] (<class 'test_example.FunctionTestCase'>) (45807376)
nose.suite: DEBUG: get ancestry <class 'test_example.FunctionTestCase'>
nose.suite: DEBUG:  <class 'test_example.FunctionTestCase'> ancestors 
['test_example']
nose: DEBUG: __import__ test_example
nose: DEBUG: resolve: [], test_example, <module 'test_example' from 
'/tmp/test_example.pyc'>, <module 'test_example' from '/tmp/test_example.pyc'>
nose.suite: DEBUG: suite <nose.suite.ContextSuite context=FunctionTestCase> 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.

Original issue reported on code.google.com by gfxm...@gmail.com on 27 May 2011 at 11:21

GoogleCodeExporter commented 9 years ago
It's generally not a good idea to use import * and in this case it appears to 
be revealing a bug in unittest where the ``__str__`` method is not quite right. 
 I guess the best thing for nose to do right here is not die a horrible death 
so I fixed that in revision a4c53cc7f81f96a06deba77895b6019ee58038dd .  
However, the result now is that you see an even more confusing error in your 
test output:

======================================================================
ERROR: str(object) -> string
----------------------------------------------------------------------
TypeError: 'str' object is not callable

----------------------------------------------------------------------

I'll leave it at that since it was better than before; this way at least your 
other tests will run.  Thanks for the bug report.

Original comment by kumar.mcmillan on 27 May 2011 at 3:09