From: Federico Caselli Date: Tue, 17 May 2022 20:26:20 +0000 (+0200) Subject: Fix warnings raised by the testing module X-Git-Tag: rel_2_0_0b1~304^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a8c4732cc8b066b4059680df40bc079d9b08009;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix warnings raised by the testing module Adjust the automatic stacklevel counter to ignore sqlalchemy.testing Properly apply warning filters Change-Id: Ib3d2eb6269af5fc72881df4d39194b3b0cbb1353 --- diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py index 53398ea31d..eae0519921 100644 --- a/lib/sqlalchemy/testing/suite/test_sequence.py +++ b/lib/sqlalchemy/testing/suite/test_sequence.py @@ -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) diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index db36a28911..db83790492 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -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) diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index a23bee8753..66354f6b64 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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