1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
from __future__ import print_function
import pytest
@pytest.fixture
def testfile(tmpdir):
tmpfile = tmpdir.join('test_execution_context')
tmpfile.write("""
from __future__ import print_function
import gc
class X(object):
def __del__(self):
print("Called", self.num)
def f():
x1 = X(); x1.num = 1
x2 = X(); x2.num = 2
x1.next = x2
f()
gc.collect()
gc.collect()
""")
return tmpfile
def test_del_not_blocked(testfile):
# test the behavior fixed in r71420: before, only one __del__
# would be called
import os, sys
if sys.platform == "win32":
cmdformat = '"%s" "%s"'
else:
cmdformat = "'%s' '%s'"
g = os.popen(cmdformat % (sys.executable, testfile), 'r')
data = g.read()
g.close()
assert 'Called 1' in data
assert 'Called 2' in data
|