Skip to content

Backport the six further assertions Python 3.14 added to unittest - #653

Merged
Paebbels merged 1 commit into
devfrom
claude/testcase-backports
Oct 25, 2026
Merged

Paebbels merged 1 commit into
devfrom
claude/testcase-backports

Conversation

@pytooling-claude

Copy link
Copy Markdown

Testcase provided only two of the eight assertions Python 3.14 added to unittest.TestCase. A test using one of the other six passed on 3.14 and failed on 3.11 to 3.13 - pyEDAA.OutputFilter's application test hit it (edaa-org/pyEDAA.OutputFilter#108).

New Features

  • pyTooling.Testing:
    • Testcase provides assertIsSubclass, assertNotIsSubclass, assertStartsWith, assertNotStartsWith, assertEndsWith and assertNotEndsWith on Python 3.11 to 3.13. They follow CPython's implementations: a tuple of classes, prefixes or suffixes, Python 3.14's messages, Expected str, not bytes for a mismatched string type, and a msg added to the message as longMessage says. On 3.14 and newer the class defines nothing, so the standard library's implementations are used.

Changes

  • pyTooling.Testing:
    • assertHasAttr and assertNotHasAttr write Python 3.14's messages for a module (module 'json' has no attribute ...) and a class (type object 'int' has ...), and add a given msg instead of replacing the message - as on 3.14.

Documentation

  • doc/Testing.rst, Assertions: a table of the eight assertions. doc/News.rst lists the six new ones.

Unit Tests

  • tests/unit/Testing/__init__.py: a new class BackportedAssertions asserts each assertion's success and its full failure messages, including tuples, the wrong string type and an added msg. The same tests run against unittest on 3.14+ and against the backports on 3.11 to 3.13 (run locally with Python 3.13: 40 passed).

Related Issues and Pull-Requests

Patrick: backport them. 'Testcase' provided only 'assertHasAttr' and
'assertNotHasAttr' on Python 3.11 to 3.13, so a test using 'assertIsSubclass',
'assertStartsWith' or 'assertEndsWith' passed on 3.14 and failed on the older
interpreters (pyEDAA.OutputFilter's application test, #108).

'Testcase' defines 'assertIsSubclass', 'assertNotIsSubclass',
'assertStartsWith', 'assertNotStartsWith', 'assertEndsWith' and
'assertNotEndsWith' under 'if version_info < (3, 14):', following CPython's
implementations: a tuple of classes, prefixes or suffixes, Python 3.14's
messages, a wrong type of string ('Expected str, not bytes'), and 'msg' added as
'longMessage' says. The type check is written out in each method rather than in
a shared helper, so a failure ends in the assertion that failed.

'assertHasAttr' and 'assertNotHasAttr' write 3.14's messages for a module and a
class now, and add 'msg' instead of replacing the message.

The module's imports share one column again ('unittest.util' was the widest).

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 25, 2026 21:46
@pytooling-claude pytooling-claude Bot added Enhancement New feature or request Unit Tests labels Oct 25, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 77 complexity · 8 duplication

Metric Results
Complexity 77
Duplication 8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Paebbels
Paebbels merged commit 96b436e into dev Oct 25, 2026
9 of 50 checks passed
@Paebbels
Paebbels deleted the claude/testcase-backports branch October 25, 2026 21:48
@pytooling-claude pytooling-claude Bot mentioned this pull request Oct 25, 2026
@pytooling-claude pytooling-claude Bot added this to the v10.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants