summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/warnings.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/testing/warnings.py')
-rw-r--r--lib/sqlalchemy/testing/warnings.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py
index 47f1e1404..640f02a78 100644
--- a/lib/sqlalchemy/testing/warnings.py
+++ b/lib/sqlalchemy/testing/warnings.py
@@ -9,7 +9,7 @@ from __future__ import absolute_import
import warnings
from .. import exc as sa_exc
-import re
+from . import assertions
def setup_filters():
@@ -22,19 +22,13 @@ def setup_filters():
def assert_warnings(fn, warning_msgs, regex=False):
- """Assert that each of the given warnings are emitted by fn."""
-
- from .assertions import eq_
-
- with warnings.catch_warnings(record=True) as log:
- # ensure that nothing is going into __warningregistry__
- warnings.filterwarnings("always")
-
- result = fn()
- for warning in log:
- popwarn = warning_msgs.pop(0)
- if regex:
- assert re.match(popwarn, str(warning.message))
- else:
- eq_(popwarn, str(warning.message))
- return result
+ """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()
+