| 72 | |
| 73 | @config.fixture() |
| 74 | def connection(self): |
| 75 | global _connection_fixture_connection |
| 76 | |
| 77 | eng = getattr(self, "bind", None) or config.db |
| 78 | |
| 79 | conn = eng.connect() |
| 80 | trans = conn.begin() |
| 81 | |
| 82 | _connection_fixture_connection = conn |
| 83 | yield conn |
| 84 | |
| 85 | _connection_fixture_connection = None |
| 86 | |
| 87 | if trans.is_active: |
| 88 | trans.rollback() |
| 89 | # trans would not be active here if the test is using |
| 90 | # the legacy @provide_metadata decorator still, as it will |
| 91 | # run a close all connections. |
| 92 | conn.close() |
| 93 | |
| 94 | @config.fixture() |
| 95 | def close_result_when_finished(self): |