mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-135120: Add test.support.subTests() (GH-135121) (GH-135208)
(cherry picked from commit 6ef06fad84
)
This commit is contained in:
parent
4e2e02eec9
commit
5b38af57e0
6 changed files with 298 additions and 333 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue