-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Description
Python 3.14 makes the warnings
module thread-safe. While testing whether we can globally allow tests that use warnings
to run on 3.14 under pytest-run-parallel, I discovered that SciPy is making heavy use of np.testing.supress_warnings
, and it isn't thread-safe:
PARALLEL FAILED scipy/cluster/tests/test_vq.py::TestKMeans::test_kmeans_lost_cluster[numpy] - AttributeError: 'suppress_warnings' object has no attribute '_orig_show'
(from logs of a SciPy test run)
The relevant SciPy test is here:
I'm not totally sure why the failure is happening - I would think each test instance would have its own private context manager instance, but the error I'm seeing makes it seem like threads are sharing the context manager.
In any case, it's clearly thread-unsafe and relies on manipulating global state stored in the warnings
module:
numpy/numpy/testing/_private/utils.py
Lines 2400 to 2402 in e740470
self._orig_show = warnings.showwarning | |
self._filters = warnings.filters | |
warnings.filters = self._filters[:] |
The whole thing should probably be implemented using a context variable instead of manipulating / relying on global state on the warnings
module.