From be6143d72acc69ae19283a936e7426e92fc35c77 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Fri, 19 Apr 2024 15:08:04 +0200 Subject: [PATCH 1/3] silent warnings --- src/silx/utils/number.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/silx/utils/number.py b/src/silx/utils/number.py index 630c79cd41..e60ab7b537 100755 --- a/src/silx/utils/number.py +++ b/src/silx/utils/number.py @@ -1,6 +1,6 @@ # /*########################################################################## # -# Copyright (c) 2016-2018 European Synchrotron Radiation Facility +# Copyright (c) 2016-2024 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -31,6 +31,7 @@ import numpy import re import logging +import warnings _logger = logging.getLogger(__name__) @@ -70,7 +71,7 @@ def is_longdouble_64bits(): def min_numerical_convertible_type(string, check_accuracy=True): """ Parse the string and try to return the smallest numerical type to use for - a safe conversion. It has some known issues: precission loss. + a safe conversion. It has some known issues: precision loss. :param str string: Representation of a float/integer with text :param bool check_accuracy: If true, a warning is pushed on the logger @@ -105,13 +106,17 @@ def min_numerical_convertible_type(string, check_accuracy=True): exponent = "0" nb_precision_digits = int(exponent) - len(decimal) - 1 - precision = _biggest_float(10) ** nb_precision_digits * 1.2 + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "overflow encountered in scalar power", RuntimeWarning) + precision = _biggest_float(10) ** nb_precision_digits * 1.2 previous_type = _biggest_float for numpy_type in _float_types: if numpy_type == _biggest_float: # value was already casted using the bigger type continue - reduced_value = numpy_type(value) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "overflow encountered in cast", RuntimeWarning) + reduced_value = numpy_type(value) if not numpy.isfinite(reduced_value): break # numpy isclose(atol=is not accurate enough) From c6d913be863b48772b20a5cb73707138cf14c561 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Fri, 19 Apr 2024 15:08:33 +0200 Subject: [PATCH 2/3] Ignore warnings for specific tests due to corner case situtation --- src/silx/gui/plot/test/testPlotWidget.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/silx/gui/plot/test/testPlotWidget.py b/src/silx/gui/plot/test/testPlotWidget.py index c79252d5c1..9a8b277991 100755 --- a/src/silx/gui/plot/test/testPlotWidget.py +++ b/src/silx/gui/plot/test/testPlotWidget.py @@ -1530,6 +1530,7 @@ def testBoundingRectArguments(self): with self.assertRaises(Exception): item.setBounds((-1000, 1000, 2000, -2000)) + @pytest.mark.filterwarnings("ignore:Attempting to set identical low and high ylims makes transformation singular; automatically expanding.:UserWarning") def testBoundingRectWithLog(self): item = BoundingRect() self.plot.addItem(item) @@ -1549,6 +1550,7 @@ def testBoundingRectWithLog(self): self.plot.getYAxis()._setLogarithmic(False) self.assertIsNone(item.getBounds()) + @pytest.mark.filterwarnings("ignore:Attempting to set identical low and high ylims makes transformation singular; automatically expanding.:UserWarning") def testAxisExtent(self): """Test XAxisExtent and yAxisExtent""" for cls, axis in ( @@ -2054,6 +2056,7 @@ class TestSpecial_ExplicitMplBackend(TestSpecialBackend): backend = "mpl" +@pytest.mark.filterwarnings("ignore:All-NaN slice encountered:RuntimeWarning") @pytest.mark.parametrize("plotWidget", ("mpl", "gl"), indirect=True) @pytest.mark.parametrize( "xerror,yerror", From 3a86f87760c4eb7da28f5b00ca317ed8d2a1f5c1 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Fri, 19 Apr 2024 15:09:33 +0200 Subject: [PATCH 3/3] Move pytest config to pyproject + configure filterwarnings --- pyproject.toml | 15 +++++++++++++++ pytest.ini | 6 ------ setup.py | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) delete mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 84c9e77d97..7c5d51fc7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,3 +11,18 @@ build-backend = "setuptools.build_meta" required-version = 23 target-version = ["py37", "py38", "py39", "py310", "py311", "py312"] safe = true + +[tool.pytest.ini_options] +minversion = "6.0" +python_files = [ + "test/test*.py", + "test/Test*.py", +] +python_classes = "Test" +python_functions = "test" +filterwarnings = [ + "error", + # note the use of single quote below to denote "raw" strings in TOML + 'ignore:tostring\(\) is deprecated. Use tobytes\(\) instead\.:DeprecationWarning:OpenGL', + 'ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning', +] diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 377f33f4aa..0000000000 --- a/pytest.ini +++ /dev/null @@ -1,6 +0,0 @@ -[pytest] -python_files = - test/test*.py - test/Test*.py -python_classes = Test -python_functions = test diff --git a/setup.py b/setup.py index 6b9f7ac33f..6ebce7c59e 100644 --- a/setup.py +++ b/setup.py @@ -189,7 +189,7 @@ def get_project_configuration(): ] test_requires = [ - "pytest", + "pytest>=6.0", "pytest-xvfb", "pytest-mock", "bitshuffle",