asynctest icon indicating copy to clipboard operation
asynctest copied to clipboard

Stacktraces for exception are useless

Open arthurdarcet opened this issue 8 years ago • 1 comments

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'

arthurdarcet avatar Dec 05 '16 14:12 arthurdarcet

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 avatar Dec 05 '16 17:12 Martiusweb