diff --git a/conftest.py b/conftest.py index d61f5277b2ba..9f2dd5516e73 100644 --- a/conftest.py +++ b/conftest.py @@ -13,6 +13,7 @@ # limitations under the License. import pytest +import numpy as np def pytest_addoption(parser): @@ -25,6 +26,12 @@ def pytest_addoption(parser): parser.addoption( "--enable-slow-tests", action="store_true", default=False, help="run slow tests" ) + parser.addoption( + "--warn-numpy-data-promotion", + action="store_true", + default=False, + help="enable NumPy 2 data type promotion warnings" + ) def pytest_collection_modifyitems(config, items): @@ -48,6 +55,11 @@ def pytest_collection_modifyitems(config, items): del skip_marks["slow"] # pragma: no cover skip_keywords = frozenset(skip_marks.keys()) + # If requested, globally enable verbose NumPy 2 warnings about data type + # promotion. See https://numpy.org/doc/2.0/numpy_2_0_migration_guide.html. + if config.option.warn_numpy_data_promotion: + np._set_promotion_state("weak_and_warn") + for item in items: for k in skip_keywords.intersection(item.keywords): item.add_marker(skip_marks[k])