Skip to content

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

Merged
pull[bot] merged 8 commits into
sysfce2:masterfrom
testing-cabal:master
Mar 26, 2026
Merged

[pull] master from testing-cabal:master#82
pull[bot] merged 8 commits into
sysfce2:masterfrom
testing-cabal:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented Mar 26, 2026

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

stephenfin and others added 8 commits March 26, 2026 15:47
We no longer care about Python < 2.7. Or Python == 2.7 for that matter.
However, we do care about the additional functionality that our version
of TestProgram exposes, none of which has been successfully upstreamed
yet. This unfortunately means duplicating a lot of TestProgram's
implementation due to python/cpython#67049.

Reflect this reality in the code.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This function returns the provided argument as-is if it is either a
TextIOWrapper or StringIO. On Python 3, those are the only two types the
stdout can ever be. At runtime we will pass sys.stdout, which is a
TextIOWrapper, and in our tests we will pass a StringIO. This call is
therefore unnecessary and can be dropped and the function marked as
deprecated since it has no other users.

This change also highlights an issue with our types for TextTestResult.
We had indicated that the `stream` parameter for same had to be a
TextIO, which was considerably narrower than the IO[str] we have typed
the `stdout` parameter of TestToolsTestRunner as being. It turns out
TextTestResult is only using write() and flush(), both of which are
defined on IO[str], thus we can broaden its type, removing a `type:
ignore` in the process.

Signed-off-by: Stephen Finucane <stephen@that.guru>
These all duplicate what is provided by the typeshed stubs or whta is
inferred by our definitions in __init__. Remove them.

Signed-off-by: Stephen Finucane <stephen@that.guru>
We were using `functools.partial` to pre-populate the `stdout` parameter
of the test runner instance passed to `TestProgram`. However, the
`_get_runner` method will be called if we do not pass a `testRunner`
argument and *that* will attempt to populate the `stdout` property with
`self.stdout`.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
This try-except was necessary to support an instance of a runner being
passed that did not support the `tb_locals` parameter. This appears to
be a compat handler for Python 2.x variants of `TextTestRunner`, which
did not accept this parameter [1]. This is not the case of the lowest
version of Python we currently support, 3.10 [2], meaning we can remove
the wrapper.

[1] https://github.com/python/cpython/blob/v2.7.1/Lib/unittest/runner.py#L127-L128
[2] https://github.com/python/cpython/blob/v3.10.0/Lib/unittest/runner.py#L128-L130

Signed-off-by: Stephen Finucane <stephen@that.guru>
This try-except was only needed if we provide a test runner (via the
testRunner parameter) that was not an instance of TestToolsTestRunner.
While upstream might need to support this [1], we do not. Remove the
fallback.

[1] https://github.com/python/cpython/blob/v3.10.0/Lib/unittest/main.py#L251-L270

Signed-off-by: Stephen Finucane <stephen@that.guru>
Simplify TestProgram, TestToolsTestRunner
@pull pull Bot locked and limited conversation to collaborators Mar 26, 2026
@pull pull Bot added the ⤵️ pull label Mar 26, 2026
@pull pull Bot merged commit 208d2db into sysfce2:master Mar 26, 2026
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