[3.14] gh-135120: Add test.support.subTests() (GH-135121) (GH-135208)

(cherry picked from commit 6ef06fad84)
This commit is contained in:
Serhiy Storchaka 2025-06-06 16:03:28 +03:00 committed by GitHub
parent 4e2e02eec9
commit 5b38af57e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 298 additions and 333 deletions

View file

@ -6,6 +6,7 @@ import subprocess
import sys
import unittest
import warnings
from test import support
from test.support import cpython_only, os_helper
from test.support import TestFailed
from ntpath import ALLOW_MISSING
@ -79,24 +80,7 @@ def tester(fn, wantResult):
def _parameterize(*parameters):
"""Simplistic decorator to parametrize a test
Runs the decorated test multiple times in subTest, with a value from
'parameters' passed as an extra positional argument.
Calls doCleanups() after each run.
Not for general use. Intended to avoid indenting for easier backports.
See https://discuss.python.org/t/91827 for discussing generalizations.
"""
def _parametrize_decorator(func):
def _parameterized(self, *args, **kwargs):
for parameter in parameters:
with self.subTest(parameter):
func(self, *args, parameter, **kwargs)
self.doCleanups()
return _parameterized
return _parametrize_decorator
return support.subTests('kwargs', parameters, _do_cleanups=True)
class NtpathTestCase(unittest.TestCase):