Created
April 27, 2015 17:08
-
-
Save nicoddemus/d30c616122e30c938b6b to your computer and use it in GitHub Desktop.
Test instance deletion (pytest runner, both pytest style class and xUnit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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