micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

- show traceback when test failed

Open maho opened this issue 4 years ago • 6 comments

i was surprised that exception in tested function is just silently redirected to nowhere.

I think it's good to show the traceback.

maho avatar Apr 24 '21 23:04 maho

Is this the same as what CPython does?

stinos avatar Apr 25 '21 13:04 stinos

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.

maho avatar Apr 25 '21 15:04 maho

Makes sense. Adding a newline would be nice though because raising multiple exceptions results in text which gets hard to read.

stinos avatar Apr 26 '21 14:04 stinos

should I do any more changes or it's ok?

maho avatar Jun 02 '21 23:06 maho

@stinos? Anyone?

maho avatar Jul 26 '21 10:07 maho

I think this is ok, but it's not up to me to merge it :)

stinos avatar Jul 26 '21 10:07 stinos