diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-01-09 23:44:58 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-01-09 23:44:58 +0000 |
commit | 38641b93eafe90ca17770559c8be4b187ec117bb (patch) | |
tree | 8f7ca417157be24f1b84e0f2f2437ea3241badeb /tests/testutils.py | |
parent | 15a09da96d7e622de6b0571fac171fc2253c8a8f (diff) | |
download | psycopg2-38641b93eafe90ca17770559c8be4b187ec117bb.tar.gz |
Test decorator moved into the test utilities module
Diffstat (limited to 'tests/testutils.py')
-rw-r--r-- | tests/testutils.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index 6d04fc0..e0b8eaf 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -88,3 +88,30 @@ def skip_if_no_pg_sleep(name): return skip_if_no_pg_sleep__ return skip_if_no_pg_sleep_ + + +def skip_if_tpc_disabled(f): + """Skip a test if the server has tpc support disabled.""" + def skip_if_tpc_disabled_(self): + from psycopg2 import ProgrammingError + cnn = self.connect() + cur = cnn.cursor() + try: + cur.execute("SHOW max_prepared_transactions;") + except ProgrammingError: + return self.skipTest( + "server too old: two phase transactions not supported.") + else: + mtp = int(cur.fetchone()[0]) + cnn.close() + + if not mtp: + return self.skipTest( + "server not configured for two phase transactions. " + "set max_prepared_transactions to > 0 to run the test") + return f(self) + + skip_if_tpc_disabled_.__name__ = f.__name__ + return skip_if_tpc_disabled_ + + |