Files
sqlalchemy/lib/sqlalchemy/testing/warnings.py
T
Mike Bayer 01c50c64e3 Remove all remaining removed_in_20 warnings slated for removal
Finalize all remaining removed-in-2.0 changes so that we
can begin doing pep-484 typing without old things
getting in the way (we will also have to do public_factory).

note there are a few "moved_in_20()" and "became_legacy_in_20()"
warnings still in place.  The SQLALCHEMY_WARN_20 variable
is now removed.

Also removed here are the legacy "in place mutators" for Select
statements, and some keyword-only argument signatures in Core
have been added.

Also in the big change department, the ORM mapper() function
is removed entirely; the Mapper class is otherwise unchanged,
just the public-facing API function.  Mappers are now always
given a registry in which to participate, however the
argument signature of Mapper is not changed. ideally "registry"
would be the first positional argument.

Fixes: #7257

Change-Id: Ic70c57b9f1cf7eb996338af5183b11bdeb3e1623
2022-01-05 19:28:49 -05:00

70 lines
1.9 KiB
Python

# testing/warnings.py
# Copyright (C) 2005-2021 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
import warnings
from . import assertions
from .. import exc as sa_exc
from ..util.langhelpers import _warnings_warn
class SATestSuiteWarning(sa_exc.SAWarning):
"""warning for a condition detected during tests that is non-fatal"""
def warn_test_suite(message):
_warnings_warn(message, category=SATestSuiteWarning)
def setup_filters():
"""Set global warning behavior for the test suite."""
warnings.filterwarnings(
"ignore", category=sa_exc.SAPendingDeprecationWarning
)
warnings.filterwarnings("error", category=sa_exc.SADeprecationWarning)
warnings.filterwarnings("error", category=sa_exc.SAWarning)
warnings.filterwarnings("always", category=SATestSuiteWarning)
# some selected deprecations...
warnings.filterwarnings("error", category=DeprecationWarning)
warnings.filterwarnings(
"ignore", category=DeprecationWarning, message=r".*StopIteration"
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r".*inspect.get.*argspec",
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message="The loop argument is deprecated",
)
try:
import pytest
except ImportError:
pass
else:
warnings.filterwarnings(
"once", category=pytest.PytestDeprecationWarning
)
def assert_warnings(fn, warning_msgs, regex=False):
"""Assert that each of the given warnings are emitted by fn.
Deprecated. Please use assertions.expect_warnings().
"""
with assertions._expect_warnings(
sa_exc.SAWarning, warning_msgs, regex=regex
):
return fn()