TST: Use correct method of clearing mock objects#31153
Merged
ksunden merged 1 commit intomatplotlib:mainfrom Feb 13, 2026
Merged
TST: Use correct method of clearing mock objects#31153ksunden merged 1 commit intomatplotlib:mainfrom
ksunden merged 1 commit intomatplotlib:mainfrom
Conversation
In Python 3.13.12 and 3.14.3, fixes for thread-safety of mock `call_count` meant that manually changing it no longer works [1]. Instead use the more correct `reset_mock` method. [1] python/cpython#142651 (comment)
greglucas
approved these changes
Feb 13, 2026
2 tasks
timhoffm
approved these changes
Feb 13, 2026
tacaswell
approved these changes
Feb 13, 2026
Member
That is a failure I have never seen before. |
Member
|
Restarted the job to see if it is transient. |
Member
|
I‘ve seen this error somewhere before, but don’t remember where. |
Member
|
Tests passed on re-run, something to keep an eye out for if we see it more, but treating as a one-off until then, and this is a patch which fixes our tests, so merging now |
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Feb 13, 2026
bmw
pushed a commit
to certbot/certbot
that referenced
this pull request
Feb 13, 2026
…tation means it can no longer just be set to 0 (#10576) This should fix our failing tests. Python 3.14.3 has the following in its changelog: > [gh-142651](python/cpython#142651): [unittest.mock](https://docs.python.org/3/library/unittest.mock.html#module-unittest.mock): fix a thread safety issue where [Mock.call_count](https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.call_count) may return inaccurate values when the mock is called concurrently from multiple threads. As a result, we have to call `reset_mock()` instead of using `.call_count = 0`. See example [here](matplotlib/matplotlib#31153). Tests on my machine showing that this change fixes things, and it's the only place to fix: ```bash $ brew upgrade pyenv $ pyenv install 3.14.3 $ pyenv global 3.14.3 $ tools/venv.py $ source venv/bin/activate $ pytest certbot -k "test_rollback_too_many" ====================================================================== test session starts ======================================================================= platform darwin -- Python 3.14.3, pytest-9.0.2, pluggy-1.6.0 rootdir: /Users/erica/certbot configfile: pytest.ini plugins: anyio-4.12.1, xdist-3.8.0, cov-7.0.0 collected 1039 items / 1038 deselected / 1 selected certbot/src/certbot/_internal/tests/reverter_test.py . [100%] =============================================================== 1 passed, 1038 deselected in 2.94s =============================================================== $ git grep 'call_count = 0' $ git checkout main $ pytest certbot -k "test_rollback_too_many" ====================================================================== test session starts ======================================================================= platform darwin -- Python 3.14.3, pytest-9.0.2, pluggy-1.6.0 rootdir: /Users/erica/certbot configfile: pytest.ini plugins: anyio-4.12.1, xdist-3.8.0, cov-7.0.0 collected 1039 items / 1038 deselected / 1 selected certbot/src/certbot/_internal/tests/reverter_test.py F [100%] ============================================================================ FAILURES ============================================================================ _______________________________________________________ TestFullCheckpointsReverter.test_rollback_too_many _______________________________________________________ self = <certbot._internal.tests.reverter_test.TestFullCheckpointsReverter testMethod=test_rollback_too_many> mock_logger = <MagicMock name='logger' id='4463351456'> > ??? E AssertionError: assert 2 == 1 E + where 2 = <MagicMock name='logger.warning' id='4463351792'>.call_count E + where <MagicMock name='logger.warning' id='4463351792'> = <MagicMock name='logger' id='4463351456'>.warning certbot/src/certbot/_internal/tests/reverter_test.py:363: AssertionError ==================================================================== short test summary info ===================================================================== FAILED certbot/src/certbot/_internal/tests/reverter_test.py::TestFullCheckpointsReverter::test_rollback_too_many - AssertionError: assert 2 == 1 =============================================================== 1 failed, 1038 deselected in 0.48s =============================================================== $ git grep 'call_count = 0' certbot/src/certbot/_internal/tests/reverter_test.py: mock_logger.warning.call_count = 0 ```
timhoffm
added a commit
that referenced
this pull request
Feb 13, 2026
…153-on-v3.10.x Backport PR #31153 on branch v3.10.x (TST: Use correct method of clearing mock objects)
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR summary
In Python 3.13.12 and 3.14.3, fixes for thread-safety of mock
call_countmeant that manually changing it no longer works [1]. Instead use the more correctreset_mockmethod.[1] python/cpython#142651 (comment)
Fixes #31112
PR checklist