diff options
| author | Gord Thompson <gord@gordthompson.com> | 2020-02-13 12:14:42 -0700 |
|---|---|---|
| committer | Gord Thompson <gord@gordthompson.com> | 2020-02-17 10:15:12 -0700 |
| commit | 60f627cbd0d769e65353e720548efac9d8ab95d9 (patch) | |
| tree | 2370558b27263eeeae1f6731d39d80f2483b18e0 /lib/sqlalchemy/testing/fixtures.py | |
| parent | 3c7765b49c0aba253c11f435b2923bb488d15809 (diff) | |
| download | sqlalchemy-60f627cbd0d769e65353e720548efac9d8ab95d9.tar.gz | |
Replace engine.execute w/ context manager (step1)
First (baby) step at replacing engine.execute
calls in test code with the new preferred way
of executing. MSSQL was targeted because it was
the easiest for me to test locally.
Change-Id: Id2e02f0e39007cbfd28ca6a535115f53c6407015
Diffstat (limited to 'lib/sqlalchemy/testing/fixtures.py')
| -rw-r--r-- | lib/sqlalchemy/testing/fixtures.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 62bf9fc1f..bae0cee89 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -56,6 +56,32 @@ class TestBase(object): if hasattr(self, "tearDown"): self.tearDown() + @config.fixture() + def connection(self): + conn = config.db.connect() + trans = conn.begin() + try: + yield conn + finally: + trans.rollback() + conn.close() + + # propose a replacement for @testing.provide_metadata. + # the problem with this is that TablesTest below has a ".metadata" + # attribute already which is accessed directly as part of the + # @testing.provide_metadata pattern. Might need to call this _metadata + # for it to be useful. + # @config.fixture() + # def metadata(self): + # """Provide bound MetaData for a single test, dropping afterwards.""" + # + # from . import engines + # metadata = schema.MetaData(config.db) + # try: + # yield metadata + # finally: + # engines.drop_all_tables(metadata, config.db) + class TablesTest(TestBase): |
