Skip to content

Commit

Permalink
Suppress nonsense DeprecationWarning caused by unittest
Browse files Browse the repository at this point in the history
`unittest.TestCase.assertWarns` in context-manager form has an awkward
habit of sticking a `__warningregistry__` attribute on every module in
existence, then querying the modules for it later.  This interacts
poorly with a Numpy 2 deprecation warning trigger for code that's
attempting to import functions from modules that became private in Numpy
2.

This simply suppresses that particular warning from the test suite.
  • Loading branch information
jakelishman committed Jun 28, 2024
1 parent ea5a54b commit 541dae4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ def setUpClass(cls):
warnings.filterwarnings("error", category=DeprecationWarning)
warnings.filterwarnings("error", category=QiskitWarning)

# Numpy 2 made a few new modules private, and have warnings that trigger if you try to
# access attributes that _would_ have existed. Unfortunately, Python's `unittest` has a
# tendency to add `__warningregistry__` attributes on every module in existence when we
# enter a `TestCase.assertWarns` context manager, which can then trick Numpy into sending
# out a nonsense `DeprecationWarning`.
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message="__warningregistry__",
module=r"numpy(\.\w+)*",
)

# We only use pandas transitively through seaborn, so it's their responsibility to mark if
# their use of pandas would be a problem.
warnings.filterwarnings(
Expand Down

0 comments on commit 541dae4

Please sign in to comment.