Use errors module to catch a specific postgres error

This commit is contained in:
Daniele Varrazzo 2019-03-16 19:07:27 +00:00
parent b0119fef81
commit e8135ee2cf

View File

@ -34,6 +34,7 @@ from functools import wraps
from ctypes.util import find_library from ctypes.util import find_library
import psycopg2 import psycopg2
import psycopg2.errors
import psycopg2.extensions import psycopg2.extensions
from psycopg2.compat import text_type from psycopg2.compat import text_type
@ -372,12 +373,8 @@ def skip_if_no_superuser(f):
def skip_if_no_superuser_(self): def skip_if_no_superuser_(self):
try: try:
return f(self) return f(self)
except psycopg2.ProgrammingError as e: except psycopg2.errors.InsufficientPrivilege:
import psycopg2.errorcodes self.skipTest("skipped because not superuser")
if e.pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE:
self.skipTest("skipped because not superuser")
else:
raise
return skip_if_no_superuser_ return skip_if_no_superuser_