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

unittest2 not compatible with unittest result objects. #93

Open
GoogleCodeExporter opened this issue Mar 13, 2015 · 4 comments
Open

unittest2 not compatible with unittest result objects. #93

GoogleCodeExporter opened this issue Mar 13, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Download 0.8.0 release 
2. Unpack it
3. Run tests

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

Tests should have passed

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

0.8.0, Debian sid

Please provide any additional information below.

The backtrace is:

======================================================================
ERROR: testGetNestedSubTestDescriptionWithoutDocstring 
(unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zyga/unittest2-0.8.0/unittest2/test/test_result.py", line 299, in testGetNestedSubTestDescriptionWithoutDocstring
    result.getDescription(self._subtest),
  File "/home/zyga/unittest2-0.8.0/unittest2/runner.py", line 50, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithMultiLineDocstring 
(unittest2.test.test_result.Test_TestResult)
Tests getDescription() for a method with a longer docstring.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zyga/unittest2-0.8.0/unittest2/test/test_result.py", line 349, in testGetSubTestDescriptionWithMultiLineDocstring
    result.getDescription(self._subtest),
  File "/home/zyga/unittest2-0.8.0/unittest2/runner.py", line 50, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithOneLineDocstring 
(unittest2.test.test_result.Test_TestResult)
Tests getDescription() for a method with a docstring.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zyga/unittest2-0.8.0/unittest2/test/test_result.py", line 321, in testGetSubTestDescriptionWithOneLineDocstring
    result.getDescription(self._subtest),
  File "/home/zyga/unittest2-0.8.0/unittest2/runner.py", line 50, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithoutDocstring 
(unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zyga/unittest2-0.8.0/unittest2/test/test_result.py", line 276, in testGetSubTestDescriptionWithoutDocstring
    result.getDescription(self._subtest),
  File "/home/zyga/unittest2-0.8.0/unittest2/runner.py", line 50, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithoutDocstringAndParams 
(unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zyga/unittest2-0.8.0/unittest2/test/test_result.py", line 290, in testGetSubTestDescriptionWithoutDocstringAndParams
    result.getDescription(self._subtest),
  File "/home/zyga/unittest2-0.8.0/unittest2/runner.py", line 50, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'


Original issue reported on code.google.com by [email protected] on 4 Mar 2015 at 12:25

@GoogleCodeExporter
Copy link
Author

14:03 < zyga> p1otr: I've reported it upstream, I'm about to dig into the code 
to see what's broken 
14:04 < zyga> https://code.google.com/p/unittest-ext/issues/detail?id=93
14:07 < zyga> all of them are related to self._subtest being None
14:09 < zyga> ha
14:10 < zyga> and that's all broken because _Outcome object is flagged as 
result_supports_subtest=False
14:10 < zyga> weird
14:12 < zyga> ok, I get it now, it's broken iif you run tests with the unittest 
(no 2) version on the outside
14:12 < zyga> as the result object is the original one from python
14:12 < zyga> I wonder if setup.py will just always break in this case
14:14 < p1otr> PYTHONPATH?
14:15 < zyga> p1otr: no, just ./setup.py test using stock unittest by default
14:15 < zyga> p1otr: tests pass if I run python -m unittest2
14:15 < zyga> I guess that's a dh override 
14:15 < zyga> and the bug is somewhat invalid (I would love it upstream was 
better at making that discoverable, no pun intended)
14:16 < zyga> p1otr: (stock unittest doesn't have addSubTest which is breaking 
tests for that particular feature due to weird auto-detection done by unittest2
14:16 < p1otr> dh_auto_test -- --system=custom --test-args='{interpreter} -m 
unittest2'
14:16 < zyga> p1otr: thanks, checkin
14:18 < zyga> p1otr: yep, all green, thanks! :)

Original comment by [email protected] on 4 Mar 2015 at 1:18

@GoogleCodeExporter
Copy link
Author

So this is an API break, obviously. We inherited it from upstream unittest, and 
I think that it would be reasonable to fix it there (in that any duck-typed 
older Result object should be usable). If you care to file a bug there about it 
I'll see about getting it addressed before 3.5 releases. Whether thats nagging 
someone or doing it myself :)

Original comment by [email protected] on 12 Mar 2015 at 2:45

  • Changed title: unittest2 not compatible with unittest result objects.
  • Changed state: Accepted

@axelpale
Copy link

Ran into this bug with the following configuration:

  • python 2.7.5
  • nose2 0.5.0
  • unittest2 1.1.0

My package is named nudged. Its setup.py includes:

...
tests_require=['nose2', 'unittest2'],
test_suite='nose2.collector.collector'
...

Now, when running python setup.py test to test the package, somehow the tests in the unittest2 egg are ran, producing the following output:

running test
running egg_info
writing nudged.egg-info/PKG-INFO
writing top-level names to nudged.egg-info/top_level.txt
writing dependency_links to nudged.egg-info/dependency_links.txt
reading manifest file 'nudged.egg-info/SOURCES.txt'
writing manifest file 'nudged.egg-info/SOURCES.txt'
running build_ext
...........................................................................s........s..............................................................................................s.............................................................................................................................EEEEE....................................................................................
======================================================================
ERROR: testGetNestedSubTestDescriptionWithoutDocstring (unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/test/test_result.py", line 333, in testGetNestedSubTestDescriptionWithoutDocstring
    result.getDescription(self._subtest),
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/runner.py", line 52, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithMultiLineDocstring (unittest2.test.test_result.Test_TestResult)
Tests getDescription() for a method with a longer docstring.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/test/test_result.py", line 383, in testGetSubTestDescriptionWithMultiLineDocstring
    result.getDescription(self._subtest),
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/runner.py", line 52, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithOneLineDocstring (unittest2.test.test_result.Test_TestResult)
Tests getDescription() for a method with a docstring.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/test/test_result.py", line 355, in testGetSubTestDescriptionWithOneLineDocstring
    result.getDescription(self._subtest),
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/runner.py", line 52, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithoutDocstring (unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/test/test_result.py", line 310, in testGetSubTestDescriptionWithoutDocstring
    result.getDescription(self._subtest),
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/runner.py", line 52, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

======================================================================
ERROR: testGetSubTestDescriptionWithoutDocstringAndParams (unittest2.test.test_result.Test_TestResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/test/test_result.py", line 324, in testGetSubTestDescriptionWithoutDocstringAndParams
    result.getDescription(self._subtest),
  File "/Users/xeli/workspace/nudged-py/unittest2-1.1.0-py2.7.egg/unittest2/runner.py", line 52, in getDescription
    doc_first_line = test.shortDescription()
AttributeError: 'NoneType' object has no attribute 'shortDescription'

----------------------------------------------------------------------
Ran 394 tests in 0.525s

FAILED (errors=5, skipped=3)

Annoying.

@axelpale
Copy link

For me the problem was solved by restricting nose2 to run only the tests under tests/ by adding following line to setup.cfg:

[unittest]
start-dir = tests

However, it feels a bit awkward to use unittest2 while knowing its own tests do not pass.

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

2 participants