Skip to content

[pull] master from testing-cabal:master - #102

Merged
pull[bot] merged 4 commits into
sysfce2:masterfrom
testing-cabal:master
Sep 15, 2026
Merged

pull[bot] merged 4 commits into
sysfce2:masterfrom
testing-cabal:master

Conversation

@pull

@pull pull Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

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 : )

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
@pull pull Bot locked and limited conversation to collaborators Sep 15, 2026
@pull pull Bot added the ⤵️ pull label Sep 15, 2026
@pull
pull Bot merged commit a72490e into sysfce2:master Sep 15, 2026
0 of 8 checks passed
@pull
pull Bot deployed to release September 15, 2026 00:25 Active

This branch was successfully deployed

1 active deployment
release — a72490ee Deployed Sep 15, 2026 by pull[bot] via build #54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants