TST: Use correct method of clearing mock objects by QuLogic · Pull Request #31153 · matplotlib/matplotlib · GitHub
Skip to content

TST: Use correct method of clearing mock objects#31153

Merged
ksunden merged 1 commit into
matplotlib:mainfrom
QuLogic:fix-mock-usage
Feb 13, 2026
Merged

TST: Use correct method of clearing mock objects#31153
ksunden merged 1 commit into
matplotlib:mainfrom
QuLogic:fix-mock-usage

Conversation

@QuLogic

@QuLogic QuLogic commented Feb 13, 2026

Copy link
Copy Markdown
Member

PR summary

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)

Fixes #31112

PR checklist

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)
@QuLogic QuLogic mentioned this pull request Feb 13, 2026
2 tasks
@tacaswell

Copy link
Copy Markdown
Member

@tacaswell

Copy link
Copy Markdown
Member

Restarted the job to see if it is transient.

@timhoffm

Copy link
Copy Markdown
Member

I‘ve seen this error somewhere before, but don’t remember where.

@ksunden

ksunden commented Feb 13, 2026

Copy link
Copy Markdown
Member

@ksunden ksunden merged commit d3b539c into matplotlib:main Feb 13, 2026
54 of 55 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 13, 2026
@QuLogic QuLogic deleted the fix-mock-usage branch February 13, 2026 19:23
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)
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Feb 18, 2026
https://build.opensuse.org/request/show/1333726
by user dgarcia + anag_factory
- TST: Use correct method of clearing mock objects
- Upstream patch correct-reset-mock.patch, gh#matplotlib/matplotlib#31153
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
…t-of-pr-31153-on-v3.10.x

Backport PR matplotlib#31153 on branch v3.10.x (TST: Use correct method of clearing mock objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TST] Upcoming dependency test failures

5 participants