From 693a6cd75c23e1ffed07ec3d92c346c57b6b370c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 28 Nov 2017 15:51:49 +0000 Subject: [PATCH] skip_if_no_getrefcount restored --- tests/test_cursor.py | 4 +++- tests/testutils.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_cursor.py b/tests/test_cursor.py index d65b93a6..e97e817b 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -27,7 +27,8 @@ import pickle import psycopg2 import psycopg2.extensions from testutils import (unittest, ConnectingTestCase, skip_before_postgres, - slow, skip_if_no_superuser, skip_if_windows) + skip_if_no_getrefcount, slow, skip_if_no_superuser, + skip_if_windows) import psycopg2.extras @@ -104,6 +105,7 @@ class CursorTests(ConnectingTestCase): self.assertEqual(b'SELECT 10.3;', cur.mogrify("SELECT %s;", (Decimal("10.3"),))) + @skip_if_no_getrefcount def test_mogrify_leak_on_multiple_reference(self): # issue #81: reference leak when a parameter value is referenced # more than once from a dict. diff --git a/tests/testutils.py b/tests/testutils.py index f3e70b39..bd08d6c7 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -350,6 +350,16 @@ def skip_if_green(reason): skip_copy_if_green = skip_if_green("copy in async mode currently not supported") +def skip_if_no_getrefcount(f): + @wraps(f) + def skip_if_no_getrefcount_(self): + if not hasattr(sys, 'getrefcount'): + return self.skipTest('skipped, no sys.getrefcount()') + else: + return f(self) + return skip_if_no_getrefcount_ + + def skip_if_windows(f): """Skip a test if run on windows""" @wraps(f)