From 2aea86a2a596323e9c8e41275acbffa1e9a609a0 Mon Sep 17 00:00:00 2001 From: Doug Burke Date: Mon, 17 Jul 2023 11:33:29 -0400 Subject: [PATCH 1/2] Silence test warnings if pytest-doctestplus is not installed I originally tried adding the warnings to sherpa/conftest.py but this is happening in pytest itself, so I've taken advantage of the general filter-warnings capability to hide thse messages. Before this change, running pytest without pytest-doctestplus would result in messages like ==================================================== warnings summary ===================================================== ../../../lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373 /lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: doctest_norecursedirs self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") ../../../lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373 /lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: doctest_plus self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") ../../../lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373 /lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: doctest_plus_atol self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") ../../../lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373 /lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: doctest_subpackage_requires self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") ../../../lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373 /lagado2.real/local/anaconda/envs/sherpa-main/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: text_file_format self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ================================================= short test summary info ================================================= --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytest.ini b/pytest.ini index fde2ab8e0c..e2c4c4847e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,6 +2,10 @@ addopts = -rs --ignore=setup.py --ignore=test_requirements.txt norecursedirs = .git build dist tmp* .eggs text_file_format = rst +filterwarnings = + # Since we can runpytest without loading pytest-doctestplus, hide + # the warnings we get when this is done + ignore::pytest.PytestConfigWarning doctest_plus = enabled doctest_plus_atol = 1e-4 doctest_optionflags = From 14e43a098ecb9a5068d2886f6d4680b9cd878404 Mon Sep 17 00:00:00 2001 From: Doug Burke Date: Mon, 17 Jul 2023 12:05:21 -0400 Subject: [PATCH 2/2] Tests: hide NumPy 1.25 ndim > 0 warnings (crates) Although Sherpa has been updated to remove the deprecation warnnng from NumPy 1.25: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.) it is still present in Crates (mid 2023), so hide the warning with the assumption we can revert this commit by mid December 2023. --- sherpa/conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sherpa/conftest.py b/sherpa/conftest.py index 97979b4e4b..339f252a51 100644 --- a/sherpa/conftest.py +++ b/sherpa/conftest.py @@ -117,6 +117,11 @@ def pytest_collection_modifyitems(config, items): r'np.asscalar\(a\) is deprecated since NumPy v1.16, use a.item\(\) instead', r"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working", + # NumPy 1.25 warnings that are raised by (mid-2023) crates code. + # Hopefully this can be removed by December 2023. + # + r"Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. \(Deprecated NumPy 1.25.\)", + ], UserWarning: [