-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Added helper to test.support for parameterizing tests #135120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Jun 4, 2025
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Jun 4, 2025
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Jun 4, 2025
@picnixz I think you suggested this exact thing a little while ago! |
encukou
pushed a commit
that referenced
this issue
Jun 6, 2025
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Jun 6, 2025
(cherry picked from commit 6ef06fa) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Jun 6, 2025
(cherry picked from commit 6ef06fa) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka
added a commit
that referenced
this issue
Jun 6, 2025
serhiy-storchaka
added a commit
that referenced
this issue
Jun 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This is a simple decorator modeled after
pytest.mark.parametrize
. It allows to "parametrize" tests, each parametrized test is run as a subtest.The decorator specifies the name(s) of parameters (as an iterable or a comma separated string) and their values (an iterable of values for parameters):
is equivalent to
It allows to save 2 levels of indentation.
Multiple decorators can be used, this generates a Descartes production of parameter values:
is equivalent to
It allows to save even more 2 levels of indentation.
It has also optional keyword-only parameter
_do_cleanups
._do_cleanups=True
tells to calldoCleanups()
after each subtest. This is temporary feature, only for use in test_ntpath. In general, it is wrong to do this becausedoCleanups()
will also calls callbacks added insetUp
. It will be replaced either byaddSubTestCleanup()
(see https://discuss.python.org/t/unittest-add-addcleanup-to-subtest/91827 and #134079) or by other methods (for example by adding fences for cleanup). Also, it will not be needed for real test parameterization.There are differences from "real" parameterization:
setUp
andtearDown
are only run once, before and after all subtests.I plan to implement real parameterization, this is why I only propose to add that decorator in
test.support
, not inunittest
. In any case it would be backported intest.support
. We may finally add both decorators inunittest
if this does not create confusion.The name
subTests
is intentionally chosen to not confuse withparametrize
which is reserved for real test parameterization.The PR contains also several examples of using that decorator.
Linked PRs
The text was updated successfully, but these errors were encountered: