diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -482,9 +482,12 @@ def test__testcapi(self): for name in dir(_testcapi): if name.startswith('test_'): - with self.subTest("internal", name=name): - test = getattr(_testcapi, name) - test() + try: + with self.subTest("internal", name=name): + test = getattr(_testcapi, name) + test() + except unittest.SkipTest: + pass if __name__ == "__main__": unittest.main() diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -10,6 +10,7 @@ import collections import contextlib import traceback +import os from . import result from .util import (strclass, safe_repr, _count_diff_all_purpose, @@ -360,6 +361,11 @@ _classSetupFailed = False + if 'SUBTEST_RANGE' in os.environ: + subtest_range = eval(os.environ['SUBTEST_RANGE']) + else: + subtest_range = None + def __init__(self, methodName='runTest'): """Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does @@ -380,6 +386,7 @@ self._testMethodDoc = testMethod.__doc__ self._cleanups = [] self._subtest = None + self.count = 0 # Map types to custom assertEqual functions that will compare # instances of said type in more detail to generate a more useful @@ -494,6 +501,14 @@ params_map = parent.params.new_child(params) self._subtest = _SubTest(self, msg, params_map) try: + self.count += 1 + if self.subtest_range is not None: + if (self.subtest_range and + self.count not in self.subtest_range): + raise SkipTest('Sub test number not in range.') + pfx = 'subTest# %d: %s,' % (self.count, msg) + print(pfx, str(params)[:79-len(pfx)]) + with self._outcome.testPartExecutor(self._subtest, isTest=True): yield if not self._outcome.success: diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2715,7 +2715,7 @@ test_incref_decref_API(PyObject *ob) { PyObject *obj = PyLong_FromLong(0); - Py_IncRef(obj); + Py_IncRef(ob); Py_DecRef(obj); Py_DecRef(obj); Py_RETURN_NONE;