summaryrefslogtreecommitdiff
path: root/tests/testutils.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2013-03-16 11:56:38 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2013-03-16 11:56:38 +0000
commit66d6c68dcc3a3f20742b29edbc005c7417c4b374 (patch)
treedc4c1be140a8c971f8b32939d7a19002aba83251 /tests/testutils.py
parent7abe1775d0bc037494576691172ece437dea3761 (diff)
downloadpsycopg2-66d6c68dcc3a3f20742b29edbc005c7417c4b374.tar.gz
Properly cleanup memory of broken connections
Fixed ticket #148.
Diffstat (limited to 'tests/testutils.py')
-rw-r--r--tests/testutils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/testutils.py b/tests/testutils.py
index 26551d4..068a913 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -207,6 +207,21 @@ def skip_from_python(*ver):
return skip_from_python__
return skip_from_python_
+def skip_if_no_superuser(f):
+ """Skip a test if the database user running the test is not a superuser"""
+ def skip_if_no_superuser_(self):
+ from psycopg2 import ProgrammingError
+ try:
+ return f(self)
+ except ProgrammingError, e:
+ import psycopg2.errorcodes
+ if e.pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE:
+ self.skipTest("skipped because not superuser")
+ else:
+ raise
+
+ return skip_if_no_superuser_
+
def script_to_py3(script):
"""Convert a script to Python3 syntax if required."""