3380
3379
self.assertLength(1, calls)
3383
class TestUncollectedWarnings(tests.TestCase):
3384
"""Check a test case still alive after being run emits a warning"""
3386
class Test(tests.TestCase):
3387
def test_pass(self):
3389
def test_self_ref(self):
3390
self.also_self = self.test_self_ref
3391
def test_skip(self):
3392
self.skip("Don't need")
3394
def _get_suite(self):
3395
return TestUtil.TestSuite([
3396
self.Test("test_pass"),
3397
self.Test("test_self_ref"),
3398
self.Test("test_skip"),
3401
def _run_selftest_with_suite(self, **kwargs):
3403
gc_on = gc.isenabled()
3407
tests.selftest(test_suite_factory=self._get_suite, stream=sio,
3412
output = sio.getvalue()
3413
self.assertNotContainsRe(output, "Uncollected test case.*test_pass")
3414
self.assertContainsRe(output, "Uncollected test case.*test_self_ref")
3417
def test_testsuite(self):
3418
self._run_selftest_with_suite()
3420
def test_pattern(self):
3421
out = self._run_selftest_with_suite(pattern="test_(?:pass|self_ref)$")
3422
self.assertNotContainsRe(out, "test_skip")
3424
def test_exclude_pattern(self):
3425
out = self._run_selftest_with_suite(exclude_pattern="test_skip$")
3426
self.assertNotContainsRe(out, "test_skip")
3428
def test_random_seed(self):
3429
self._run_selftest_with_suite(random_seed="now")
3431
def test_matching_tests_first(self):
3432
self._run_selftest_with_suite(matching_tests_first=True,
3433
pattern="test_self_ref$")
3435
def test_starting_with_and_exclude(self):
3436
out = self._run_selftest_with_suite(starting_with=["bt."],
3437
exclude_pattern="test_skip$")
3438
self.assertNotContainsRe(out, "test_skip")
3440
def test_additonal_decorator(self):
3441
out = self._run_selftest_with_suite(
3442
suite_decorators=[tests.TestDecorator])
3445
class TestUncollectedWarningsSubunit(TestUncollectedWarnings):
3446
"""Check warnings from tests staying alive are emitted with subunit"""
3448
_test_needs_features = [features.subunit]
3450
def _run_selftest_with_suite(self, **kwargs):
3451
return TestUncollectedWarnings._run_selftest_with_suite(self,
3452
runner_class=tests.SubUnitBzrRunner, **kwargs)
3455
3382
class TestEnvironHandling(tests.TestCase):
3457
3384
def test_overrideEnv_None_called_twice_doesnt_leak(self):