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

Stacktraces for exception are useless #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arthurdarcet
Copy link

Not entirely sure why, but without this patch, the stacktraces are absolutely useless:

Without the wrapper:

======================================================================
ERROR: test (test.books.ReadyWithoutContent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 274, in run
    self._run_test_method(testMethod)
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 45, in _run_test_method
    self.loop.run_until_complete(result)
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 200, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.0b3_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
    return future.result()
AttributeError: 'NoneType' object has no attribute 'items'

With the wrapper:

======================================================================
ERROR: test (test.books.ReadyWithoutContent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 274, in run
    self._run_test_method(testMethod)
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 44, in _run_test_method
    self.loop.run_until_complete(meth())
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 200, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.0b3_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
    return future.result()
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 41, in meth
    await result
  File "/Users/arthur/Documents/reaaad/redkeep/test/books.py", line 24, in test
    for k, v in self.expected.items():
AttributeError: 'NoneType' object has no attribute 'items'

Not entirely sure why, but without this, the stacktrace are absolutely useless:

Without the wrapper:
```
======================================================================
ERROR: test (test.books.ReadyWithoutContent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 274, in run
    self._run_test_method(testMethod)
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 45, in _run_test_method
    self.loop.run_until_complete(result)
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 200, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.0b3_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
    return future.result()
AttributeError: 'NoneType' object has no attribute 'items'
```

With the wrapper:
```
======================================================================
ERROR: test (test.books.ReadyWithoutContent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 274, in run
    self._run_test_method(testMethod)
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 44, in _run_test_method
    self.loop.run_until_complete(meth())
  File "/Users/arthur/Documents/reaaad/redkeep/.venv/lib/python3.6/site-packages/asynctest/case.py", line 200, in wrapper
    return method(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.0b3_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 449, in run_until_complete
    return future.result()
  File "/Users/arthur/Documents/reaaad/wyl/wyl/unittest.py", line 41, in meth
    await result
  File "/Users/arthur/Documents/reaaad/redkeep/test/books.py", line 24, in test
    for k, v in self.expected.items():
AttributeError: 'NoneType' object has no attribute 'items'
```
@Martiusweb
Copy link
Owner

Martiusweb commented Dec 5, 2016

Oh thanks, it's interesting.

At first glance, I'd say that since the exception is raised in Future.result(), the stack trace is overridden, while in the second case, re-raising the exception forces the interpreter to use the value of Exception.__traceback__ (the original traceback).

This behavior only exists in 3.6, so I suspect it's caused by a change in asyncio. I can investigate a bit more to see if this is something that should be addressed in asyncio or in asynctest. If we want to fix this in asynctest, there is probably a cleaner solution, but in this case we'll wait until I addressed the other regressions related to python 3.6.

With 3.5:

Traceback (most recent call last):
File "/home/martius/Code/python/asynctest/asynctest/case.py", line 274, in run
    self._run_test_method(testMethod)
File "/home/martius/Code/python/asynctest/asynctest/case.py", line 326, in _run_test_method
    self.loop.run_until_complete(result)
File "/home/martius/Code/python/asynctest/asynctest/case.py", line 200, in wrapper
    return method(*args, **kwargs)
File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
    return future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
File "/home/martius/Code/python/asynctest/plop.py", line 6, in test_foo
    {}["foo"]
KeyError: 'foo'

@Martiusweb Martiusweb force-pushed the master branch 3 times, most recently from c2e9ce1 to 967481c Compare April 3, 2019 15:30
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

Successfully merging this pull request may close these issues.

3 participants