kopia lustrzana https://github.com/micropython/micropython-lib
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 <jim.mussared@gmail.com>pull/598/head
rodzic
a5ef231e7d
commit
863a018b89
|
@ -1,3 +1,3 @@
|
||||||
metadata(version="0.10.1")
|
metadata(version="0.10.2")
|
||||||
|
|
||||||
package("unittest")
|
package("unittest")
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
def broken_func():
|
||||||
|
raise ValueError("uh oh!")
|
||||||
|
|
||||||
|
|
||||||
|
def test_func():
|
||||||
|
broken_func()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
|
@ -332,12 +332,12 @@ class TestResult:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
def _capture_exc(exc, traceback):
|
def _capture_exc(exc, exc_traceback):
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
if hasattr(sys, "print_exception"):
|
if hasattr(sys, "print_exception"):
|
||||||
sys.print_exception(exc, buf)
|
sys.print_exception(exc, buf)
|
||||||
elif traceback is not None:
|
elif traceback is not None:
|
||||||
traceback.print_exception(None, exc, traceback, file=buf)
|
traceback.print_exception(None, exc, exc_traceback, file=buf)
|
||||||
return buf.getvalue()
|
return buf.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ def _run_suite(c, test_result: TestResult, suite_name=""):
|
||||||
test_result.skipped.append((name, c, reason))
|
test_result.skipped.append((name, c, reason))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
_handle_test_exception(
|
_handle_test_exception(
|
||||||
current_test=(name, c), test_result=test_result, exc_info=sys.exc_info()
|
current_test=(name, c), test_result=test_result, exc_info=(type(ex), ex, None)
|
||||||
)
|
)
|
||||||
# Uncomment to investigate failure in detail
|
# Uncomment to investigate failure in detail
|
||||||
# raise
|
# raise
|
||||||
|
|
Ładowanie…
Reference in New Issue