Skip to content

Commit 863a018

Browse files
Andrzej Kowalczykjimmo
Andrzej Kowalczyk
authored andcommitted
unittest: Remove dependence on sys.exc_info.
This is not included by default in most builds, and isn't necessary for this module anyway. Also fix the local variable shadowing the traceback module in _capture_exc. Added test for both (works on CPython and MicroPython). Version bump to 0.10.2. Signed-off-by: Jim Mussared <[email protected]>
1 parent a5ef231 commit 863a018

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

python-stdlib/unittest/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.10.1")
1+
metadata(version="0.10.2")
22

33
package("unittest")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
3+
4+
def broken_func():
5+
raise ValueError("uh oh!")
6+
7+
8+
def test_func():
9+
broken_func()
10+
11+
12+
if __name__ == "__main__":
13+
unittest.main()

python-stdlib/unittest/unittest/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ def __add__(self, other):
332332
return self
333333

334334

335-
def _capture_exc(exc, traceback):
335+
def _capture_exc(exc, exc_traceback):
336336
buf = io.StringIO()
337337
if hasattr(sys, "print_exception"):
338338
sys.print_exception(exc, buf)
339339
elif traceback is not None:
340-
traceback.print_exception(None, exc, traceback, file=buf)
340+
traceback.print_exception(None, exc, exc_traceback, file=buf)
341341
return buf.getvalue()
342342

343343

@@ -402,7 +402,7 @@ def run_one(test_function):
402402
test_result.skipped.append((name, c, reason))
403403
except Exception as ex:
404404
_handle_test_exception(
405-
current_test=(name, c), test_result=test_result, exc_info=sys.exc_info()
405+
current_test=(name, c), test_result=test_result, exc_info=(type(ex), ex, None)
406406
)
407407
# Uncomment to investigate failure in detail
408408
# raise

0 commit comments

Comments
 (0)