From dc5a43f27deb18c38f3ccd79c89268553e7c55e5 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 20 Jul 2023 18:20:22 -0400 Subject: [PATCH] ci: fail tests on warnings (#3248) Co-authored-by: Slava Senchenko --- pytest.ini | 11 +++++++++++ tests/internal/test_deprecation_control.py | 11 ++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pytest.ini b/pytest.ini index 5e98ba5f1..20a396144 100644 --- a/pytest.ini +++ b/pytest.ini @@ -7,3 +7,14 @@ markers = slow: marks tests as slow (deselect with '-m "not slow"') log_cli = 1 log_cli_level = INFO +filterwarnings = + error + # From our own tests + ignore:__init__ is deprecated and will be removed in a future release:DeprecationWarning + ignore:deprecated_function is deprecated and will be removed in a future release, please use replacement_function:DeprecationWarning + # Python 3.7 deprecation + ignore::boto3.exceptions.PythonDeprecationWarning + # https://github.com/pytest-dev/pytest-xdist/issues/825#issuecomment-1292450429 + ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning + # Pytest warnings + ignore::pytest.PytestUnraisableExceptionWarning diff --git a/tests/internal/test_deprecation_control.py b/tests/internal/test_deprecation_control.py index 8edd00869..e5cbd9543 100644 --- a/tests/internal/test_deprecation_control.py +++ b/tests/internal/test_deprecation_control.py @@ -1,6 +1,6 @@ -import warnings from unittest import TestCase +import pytest from samtranslator.internal.deprecation_control import deprecated @@ -15,12 +15,5 @@ def deprecated_function(x, y): class TestDeprecationControl(TestCase): def test_deprecated_decorator(self): - with warnings.catch_warnings(record=True) as w: + with pytest.warns(DeprecationWarning): deprecated_function(1, 1) - self.assertEqual(len(w), 1) - self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) - self.assertIn( - "deprecated_function is deprecated and will be removed in a future release, " - "please use replacement_function", - str(w[-1].message), - )