Open
Description
Feature or enhancement
Proposal:
The unittest.subTest
context (i.e. the object you get using with
's as
clause, currently None
) should get methods to manage cleanups:
addCleanup
enterContext
doCleanups
And similar ones for IsolatedAsyncIOTestCase
.
They should do the same thing as the same methods on TestCase
, but with subtest scope.
Example usage:
for param in 'a', 'b', 'c':
with self.subTest() as sub:
tempfile = make_tempfile()
sub.addCleanup(os.unlink, tempfile)
do_actual_test(tempfile, param)
See Discuss thread for motivation/discussion.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/unittest-add-addcleanup-to-subtest/91827
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Todo