kopia lustrzana https://github.com/micropython/micropython-lib
unittest: Allow SkipTest to work within a subTest.
Signed-off-by: Damien George <damien@micropython.org>pull/935/head
rodzic
0827a31c07
commit
01047889eb
|
@ -0,0 +1,14 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
def test_subtest_skip(self):
|
||||||
|
for i in range(4):
|
||||||
|
with self.subTest(i=i):
|
||||||
|
print("sub test", i)
|
||||||
|
if i == 2:
|
||||||
|
self.skipTest("skip 2")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
|
@ -348,7 +348,13 @@ def _handle_test_exception(
|
||||||
exc = exc_info[1]
|
exc = exc_info[1]
|
||||||
traceback = exc_info[2]
|
traceback = exc_info[2]
|
||||||
ex_str = _capture_exc(exc, traceback)
|
ex_str = _capture_exc(exc, traceback)
|
||||||
if isinstance(exc, AssertionError):
|
if isinstance(exc, SkipTest):
|
||||||
|
reason = exc.args[0]
|
||||||
|
test_result.skippedNum += 1
|
||||||
|
test_result.skipped.append((current_test, reason))
|
||||||
|
print(" skipped:", reason)
|
||||||
|
return
|
||||||
|
elif isinstance(exc, AssertionError):
|
||||||
test_result.failuresNum += 1
|
test_result.failuresNum += 1
|
||||||
test_result.failures.append((current_test, ex_str))
|
test_result.failures.append((current_test, ex_str))
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -396,11 +402,6 @@ def _run_suite(c, test_result: TestResult, suite_name=""):
|
||||||
print(" FAIL")
|
print(" FAIL")
|
||||||
else:
|
else:
|
||||||
print(" ok")
|
print(" ok")
|
||||||
except SkipTest as e:
|
|
||||||
reason = e.args[0]
|
|
||||||
print(" skipped:", reason)
|
|
||||||
test_result.skippedNum += 1
|
|
||||||
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=(type(ex), ex, None)
|
current_test=(name, c), test_result=test_result, exc_info=(type(ex), ex, None)
|
||||||
|
|
Ładowanie…
Reference in New Issue