def test_cleanup(self): results = [] fixture = fixtures.FunctionFixture(lambda: 84, results.append) fixture.setUp() self.assertEqual(84, fixture.fn_result) self.assertEqual([], results) fixture.cleanUp() self.assertEqual([84], results)
def test_useFixture_uses_raise_first(self): calls = [] def raiser(ignored): calls.append('called') raise Exception('foo') fixture = fixtures.FunctionFixture(lambda:None, raiser) class SimpleTest(testtools.TestCase, TestWithFixtures): def test_foo(self): self.useFixture(fixture) result = unittest.TestResult() SimpleTest('test_foo').run(result) self.assertFalse(result.wasSuccessful()) self.assertEqual(['called'], calls)
def test_reset(self): results = [] expected = [21, 7] def setUp(): return expected.pop(0) def reset(result): results.append(('reset', result)) return expected.pop(0) fixture = fixtures.FunctionFixture(setUp, results.append, reset) fixture.setUp() self.assertEqual([], results) fixture.reset() self.assertEqual([('reset', 21)], results) self.assertEqual(7, fixture.fn_result) fixture.cleanUp() self.assertEqual([('reset', 21), 7], results)
def test_setup_only(self): fixture = fixtures.FunctionFixture(lambda: 42) fixture.setUp() self.assertEqual(42, fixture.fn_result) fixture.cleanUp() self.assertFalse(hasattr(fixture, 'fn_result'))