- show traceback when test failed
i was surprised that exception in tested function is just silently redirected to nowhere.
I think it's good to show the traceback.
Is this the same as what CPython does?
Let's check:
test_ee.py
import unittest
class MyTestCase(unittest.TestCase):
def _fn2(self):
raise Exception("this shouldn't happend, but it did")
def _fn(self):
return self._fn2()
def test_exception(self):
self._fn()
if __name__ == '__main__':
unittest.main()
micropython:
% micropython test_ee.py :( 1 21-04-25 - 17:39:17
test_exception (MyTestCase) ... FAIL
Traceback (most recent call last):
File "/home/maho/workspace/servo/dispenser/.micropython-lib/unittest/unittest.py", line 201, in run_class
File "test_ee.py", line 13, in test_exception
File "test_ee.py", line 9, in _fn
File "test_ee.py", line 6, in _fn2
Exception: this shouldn't happend, but it did
Ran 1 tests
FAILED (failures=1, errors=0)
CPython 3.8:
% python3 /tmp/test_ee.py :( 1 21-04-25 - 17:39:23
E
======================================================================
ERROR: test_exception (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test_ee.py", line 13, in test_exception
self._fn()
File "/tmp/test_ee.py", line 9, in _fn
return self._fn2()
File "/tmp/test_ee.py", line 6, in _fn2
raise Exception("this shouldn't happend, but it did")
Exception: this shouldn't happend, but it did
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
So this change makes it closer to behaviour of CPython.
Makes sense. Adding a newline would be nice though because raising multiple exceptions results in text which gets hard to read.
should I do any more changes or it's ok?
@stinos? Anyone?
I think this is ok, but it's not up to me to merge it :)