Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
warnings.py53 linesDownload Raw Back to testing
1# testing/warnings.py
2# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
7# mypy: ignore-errors
8
9from __future__ import annotations
10
11import warnings
12
13from . import assertions
14from .. import exc
15from .. import exc as sa_exc
16from ..exc import SATestSuiteWarning
17from ..util.langhelpers import _warnings_warn
18
19
20def warn_test_suite(message):
21    _warnings_warn(message, category=SATestSuiteWarning)
22
23
24def setup_filters():
25    """hook for setting up warnings filters.
26
27    SQLAlchemy-specific classes must only be here and not in pytest config,
28    as we need to delay importing SQLAlchemy until conftest.py has been
29    processed.
30
31    NOTE: filters on subclasses of DeprecationWarning or
32    PendingDeprecationWarning have no effect if added here, since pytest
33    will add at each test the following filters
34    ``always::PendingDeprecationWarning`` and ``always::DeprecationWarning``
35    that will take precedence over any added here.
36
37    """
38    warnings.filterwarnings("error", category=exc.SAWarning)
39    warnings.filterwarnings("always", category=exc.SATestSuiteWarning)
40
41
42def assert_warnings(fn, warning_msgs, regex=False):
43    """Assert that each of the given warnings are emitted by fn.
44
45    Deprecated.  Please use assertions.expect_warnings().
46
47    """
48
49    with assertions._expect_warnings(
50        sa_exc.SAWarning, warning_msgs, regex=regex
51    ):
52        return fn()
53 
codekingpro/portable-devtools · Team Ai