Skip to content

- show traceback when test failed #419

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

maho
Copy link

@maho maho commented Apr 24, 2021

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

I think it's good to show the traceback.

@stinos
Copy link

stinos commented Apr 25, 2021

Is this the same as what CPython does?

@maho
Copy link
Author

maho commented Apr 25, 2021

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.

@stinos
Copy link

stinos commented Apr 26, 2021

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

@maho maho force-pushed the unittest-exception branch from 6161049 to acd64a6 Compare April 28, 2021 14:01
@maho
Copy link
Author

maho commented Jun 2, 2021

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

@maho
Copy link
Author

maho commented Jul 26, 2021

@stinos? Anyone?

@stinos
Copy link

stinos commented Jul 26, 2021

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

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.

2 participants