better-exceptions: How to use better-exceptions with unittest?
I want to use better-exceptions to show error when using unittest. Here is my example:
test.py:
import better_exceptions
import unittest
better_exceptions.hook()
class MyTestCase(unittest.TestCase):
def add(self, a, b):
better_exceptions.hook()
return a + b
def test_add(self,):
better_exceptions.hook()
r1 = self.add(1, 2)
r2 = self.add(2, "1")
self.assertTrue(r1, r2)
if __name__ == "__main__":
unittest.main()
shell:
$ export BETTER_EXCEPTIONS=1
$ echo $BETTER_EXCEPTIONS
1
$ python3 test.py
E
======================================================================
ERROR: test_add (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 17, in test_add
r2 = self.add(2, "1")
File "test.py", line 11, in add
return a + b
TypeError: unsupported operand type(s) for +: 'int' and 'str'
----------------------------------------------------------------------
Ran 1 test in 0.004s
FAILED (errors=1)
Is there any way to use better-exceptions to print exception stack?
IssueHunt Summary
ocavue has been rewarded.
Backers (Total: $40.00)
issuehunt ($40.00)
Submitted pull Requests
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
IssueHunt has been backed by the following sponsors. Become a sponsor
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (10 by maintainers)
@ocavue yes please. 😃