Repository navigation
[pull] master from testing-cabal:master - #102
Merged
Merged
Conversation
Commit 267c0be added support for unittest.TestCase.subTest. This meant the following code: import unittest class TestSubTests(unittest.TestCase): def test_even_numbers(self): for i in range(5): with self.subTest(i=i): self.assertEqual(i % 2, 0) would list the exact values of "i" for which the test failed: $ stestr run test_example_subtest 2>&1 | grep ^Captured Captured traceback (i=1): Captured traceback (i=3): Captured traceback (i=1): Captured traceback (i=3): But the following code: import testtools class TestSubTests(testtools.TestCase): def test_even_numbers(self): for i in range(5): with self.subTest(i=i): self.assertEqual(i % 2, 0) would not produce a similar output: $ stestr run test_example_subtest_testtools 2>&1 | grep ^Captured Captured traceback: Captured traceback: This commit fixes this so that we get the same output whether we use unittest.TestCase.subTest or testtools.TestCase.subTest. Closes: #317 Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Cyril Roelandt <cyril@redhat.com>
…ols-testcase Add subTest support for testtools.TestCase
Subtest failures were buffered on the test case and replayed at the end of RunTest._run_core, bypassing testtools' own exception machinery. That lost several behaviours relative to a non-subtest failure: - a subclass overriding `skipException` had its skip reported as an error, since `subTest` caught the hardcoded `unittest.SkipTest` - `expectFailure` inside a subtest leaked the private `_ExpectedFailure` as an error instead of recording an expected failure - `MultipleExceptions` was reported verbatim rather than unpacked - details attached inside a failing subtest never reached the result - `AsynchronousDeferredRunTest._run_core` never drained the buffers, so a failing subtest reported as a pass Report each subtest as it completes instead, dispatching on the case's exception handlers and passing the details accumulated inside the block. Since reporting no longer lives in `_run_core`, the Twisted runner is covered too; it only needs to know not to also report success. Also align with unittest where the buffering had diverged. Follow-up to #630.
Report subtests through the exception handlers
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )