| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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)
[gw0] linux -- Python 3.11.14 /opt/hostedtoolcache/Python/3.11.14/x64/bin/python
173
174
fmt = '%4.2e'
175
176
@pytest.mark.parametrize('fmt', ['%4.2e', '{x:.2e}'])
177
def test_colorbar_format(fmt):
178
# make sure that format is passed properly
179
x, y = np.ogrid[-4:4:31j, -4:4:31j]
180
z = 120000*np.exp(-x**2 - y**2)
181
182
fig, ax = plt.subplots()
183
im = ax.imshow(z)
184
cbar = fig.colorbar(im, format=fmt)
185
fig.canvas.draw()
186
assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '8.00e+04'
187
188
# make sure that if we change the clim of the mappable that the
189
# formatting is *not* lost:
190
im.set_clim([4, 200])
191
fig.canvas.draw()
192
assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '2.00e+02'
193
194
# but if we change the norm:
195
im.set_norm(LogNorm(vmin=0.1, vmax=10))
196
fig.canvas.draw()
197
> assert (cbar.ax.yaxis.get_ticklabels()[0].get_text() ==
198
'$\\mathdefault{10^{-2}}$')
199
E AssertionError: assert '$\\mathdefault{10^{-1}}$' == '$\\mathdefault{10^{-2}}$'
200
E - $\mathdefault{10^{-2}}$
201
E ? ^
202
E + $\mathdefault{10^{-1}}$
203
E ? ^
204
205
lib/matplotlib/tests/test_colorbar.py:637: AssertionError
That is a failure I have never seen before. |
Sorry, something went wrong.
|
Restarted the job to see if it is transient. |
Sorry, something went wrong.
|
I‘ve seen this error somewhere before, but don’t remember where. |
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
…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 ```
…153-on-v3.10.x Backport PR #31153 on branch v3.10.x (TST: Use correct method of clearing mock objects)
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
…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)
| Back | FazBrowse Home | New Git URL |
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