Skip to content

Commit 86e2fa9

Browse files
committed
Disable capsule destructor test by default
1 parent da99144 commit 86e2fa9

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capsule.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939
import gc
40+
import os
4041
import time
4142

4243
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare, CPyExtType
@@ -114,31 +115,32 @@ class TestPyCapsule(CPyExtTestCase):
114115
cmpfunc=unhandled_error_compare
115116
)
116117

117-
def test_capsule_destructor(self):
118-
Tester = CPyExtType(
119-
"CapsuleDestructorTester",
120-
code="""
121-
static void capsule_destructor(PyObject* capsule) {
122-
PyObject* contents = (PyObject*) PyCapsule_GetPointer(capsule, "capsule");
123-
assert(PyDict_Check(contents));
124-
PyDict_SetItemString(contents, "destructor_was_here", Py_NewRef(Py_True));
125-
Py_DECREF(contents);
126-
}
127-
128-
static PyObject* create_capsule(PyObject* unused, PyObject* contents) {
129-
return PyCapsule_New(Py_NewRef(contents), "capsule", capsule_destructor);
130-
}
131-
""",
132-
tp_methods='{"create_capsule", (PyCFunction)create_capsule, METH_O | METH_STATIC, NULL}',
133-
)
134-
d = {}
135-
capsule = Tester.create_capsule(d)
136-
assert capsule
137-
assert not d
138-
del capsule
139-
start = time.time()
140-
while "destructor_was_here" not in d:
141-
if time.time() - start > 60:
142-
raise AssertionError("Capsule destructor didn't execute within timeout")
143-
gc.collect()
144-
time.sleep(0.01)
118+
if os.environ.get('GRAALPYTEST_RUN_GC_TESTS'):
119+
def test_capsule_destructor(self):
120+
Tester = CPyExtType(
121+
"CapsuleDestructorTester",
122+
code="""
123+
static void capsule_destructor(PyObject* capsule) {
124+
PyObject* contents = (PyObject*) PyCapsule_GetPointer(capsule, "capsule");
125+
assert(PyDict_Check(contents));
126+
PyDict_SetItemString(contents, "destructor_was_here", Py_NewRef(Py_True));
127+
Py_DECREF(contents);
128+
}
129+
130+
static PyObject* create_capsule(PyObject* unused, PyObject* contents) {
131+
return PyCapsule_New(Py_NewRef(contents), "capsule", capsule_destructor);
132+
}
133+
""",
134+
tp_methods='{"create_capsule", (PyCFunction)create_capsule, METH_O | METH_STATIC, NULL}',
135+
)
136+
d = {}
137+
capsule = Tester.create_capsule(d)
138+
assert capsule
139+
assert not d
140+
del capsule
141+
start = time.time()
142+
while "destructor_was_here" not in d:
143+
if time.time() - start > 60:
144+
raise AssertionError("Capsule destructor didn't execute within timeout")
145+
gc.collect()
146+
time.sleep(0.01)

0 commit comments

Comments
 (0)