diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-07 18:54:52 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-07 18:54:52 -0500 |
commit | 60e6ac8856e5f7f257e1797280d1510682ae8fb7 (patch) | |
tree | 41ada63c12c08415cc91dfdb812d85fd4430e1ca /lib/sqlalchemy/testing/assertions.py | |
parent | 1b260c7959c9b89e6a3993d5d96bc6b0918a8fb0 (diff) | |
download | sqlalchemy-60e6ac8856e5f7f257e1797280d1510682ae8fb7.tar.gz |
- rework the assert_sql system so that we have a context manager to work with,
use events that are local to the engine and to the run and are removed afterwards.
Diffstat (limited to 'lib/sqlalchemy/testing/assertions.py')
-rw-r--r-- | lib/sqlalchemy/testing/assertions.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index bf7c27a89..66d1f3cb0 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -405,13 +405,16 @@ class AssertsExecutionResults(object): cls.__name__, repr(expected_item))) return True + def sql_execution_asserter(self, db=None): + if db is None: + from . import db as db + + return assertsql.assert_engine(db) + def assert_sql_execution(self, db, callable_, *rules): - assertsql.asserter.add_rules(rules) - try: + with self.sql_execution_asserter(db) as asserter: callable_() - assertsql.asserter.statement_complete() - finally: - assertsql.asserter.clear_rules() + asserter.assert_(*rules) def assert_sql(self, db, callable_, list_, with_sequences=None): if (with_sequences is not None and |