Skip to content

Instantly share code, notes, and snippets.

@nicoddemus
Created April 27, 2015 17:08
Show Gist options
  • Save nicoddemus/d30c616122e30c938b6b to your computer and use it in GitHub Desktop.
Save nicoddemus/d30c616122e30c938b6b to your computer and use it in GitHub Desktop.
Test instance deletion (pytest runner, both pytest style class and xUnit)
from __future__ import unicode_literals
import weakref
from coilib50 import unittest
class Test(unittest.TestCase):
_TESTS = []
def test_01(self):
Test._TESTS.append(weakref.ref(self))
def test_02(self):
import gc
gc.collect()
self.assertEqual(len(Test._TESTS), 1)
self.assertIsNone(Test._TESTS[0]())
class Test2(object):
_TESTS = []
def test_pytest01(self):
Test2._TESTS.append(weakref.ref(self))
def test_pytest02(self):
import gc
gc.collect()
assert len(Test2._TESTS) == 1
assert Test2._TESTS[0]() is None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment