]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix warnings raised by the testing module
authorFederico Caselli <cfederico87@gmail.com>
Tue, 17 May 2022 20:26:20 +0000 (22:26 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Wed, 18 May 2022 21:47:25 +0000 (23:47 +0200)
Adjust the automatic stacklevel counter to ignore sqlalchemy.testing
Properly apply warning filters

Change-Id: Ib3d2eb6269af5fc72881df4d39194b3b0cbb1353

lib/sqlalchemy/testing/suite/test_sequence.py
lib/sqlalchemy/testing/warnings.py
lib/sqlalchemy/util/langhelpers.py

index 53398ea31d5d2242ff4ae32e34ab71e0b19bde46..eae051992107b928a6a00ccfc52e8e977a693845 100644 (file)
@@ -88,7 +88,7 @@ class SequenceTest(fixtures.TablesTest):
         )
 
     def test_nextval_direct(self, connection):
-        r = connection.execute(self.tables.seq_pk.c.id.default)
+        r = connection.scalar(self.tables.seq_pk.c.id.default)
         eq_(r, testing.db.dialect.default_sequence_base)
 
     @requirements.sequences_optional
@@ -139,7 +139,7 @@ class SequenceTest(fixtures.TablesTest):
             schema_translate_map={"alt_schema": config.test_schema}
         )
 
-        r = connection.execute(seq)
+        r = connection.scalar(seq)
         eq_(r, testing.db.dialect.default_sequence_base)
 
 
index db36a289112c81f81f656a16b8487e5415e34f41..db83790492a249ad28d3dc3733677fba075e966b 100644 (file)
@@ -28,9 +28,13 @@ def setup_filters():
     as we need to delay importing SQLAlchemy until conftest.py has been
     processed.
 
+    NOTE: filters on subclasses of DeprecationWarning or
+    PendingDeprecationWarning have no effect if added here, since pytest
+    will add at each test the following filters
+    ``always::PendingDeprecationWarning`` and ``always::DeprecationWarning``
+    that will take precedence over any added here.
+
     """
-    warnings.filterwarnings("ignore", category=exc.SAPendingDeprecationWarning)
-    warnings.filterwarnings("error", category=exc.SADeprecationWarning)
     warnings.filterwarnings("error", category=exc.SAWarning)
     warnings.filterwarnings("always", category=exc.SATestSuiteWarning)
 
index a23bee875341901482d623a0a5d33da6638a1ace..66354f6b642c6eac99d0ecda339168a9dce0a977 100644 (file)
@@ -1788,6 +1788,9 @@ def warn_limited(msg: str, args: Sequence[Any]) -> None:
     _warnings_warn(msg, exc.SAWarning)
 
 
+_not_sa_pattern = re.compile(r"^(?:sqlalchemy\.(?!testing)|alembic\.)")
+
+
 def _warnings_warn(
     message: Union[str, Warning],
     category: Optional[Type[Warning]] = None,
@@ -1810,7 +1813,7 @@ def _warnings_warn(
         # __globals__ of the decorated string functions we make also.
         # we generate this using {"__name__": fn.__module__}
         while frame is not None and re.match(
-            r"^(?:sqlalchemy\.|alembic\.)", frame.f_globals.get("__name__", "")
+            _not_sa_pattern, frame.f_globals.get("__name__", "")
         ):
             frame = frame.f_back  # type: ignore[assignment]
             stacklevel += 1