def test_with_data_decorates_a_generator(self): @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) for step in range(4): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) SilentTestRunner().run(suite) eq_(mock_call_log[0], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0)) eq_(mock_call_log[2], (MockLoader, 'unload')) eq_(mock_call_log[3], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[4], ('some_generator', Fixture.Data, 1)) eq_(mock_call_log[5], (MockLoader, 'unload')) eq_(mock_call_log[6], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[7], ('some_generator', Fixture.Data, 2)) eq_(mock_call_log[8], (MockLoader, 'unload')) eq_(mock_call_log[9], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[10], ('some_generator', Fixture.Data, 3))
def test_generated_error_raises_soft_exception_in_teardown(self): self.fxt.loader = AbusiveMockLoader() @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) raise RuntimeError("error raised from some_generator") for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) @raises(RuntimeError) def run_tests(): SilentTestRunner().run(suite) err = StringIO() sys.stderr = err try: try: run_tests() except Exception, e: etype, val, tb = sys.exc_info() assert 'error raised from some_generator' in str(val), ( "Unexpected: %s" % val) else:
def test_generated_error_raises_soft_exception_in_teardown(self): self.fxt.loader = AbusiveMockLoader() @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) raise RuntimeError("error raised from some_generator") for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) @raises(RuntimeError) def run_tests(): SilentTestRunner().run(suite) err = StringIO() sys.stderr = err try: try: run_tests() except Exception, e: etype, val, tb = sys.exc_info() assert 'error raised from some_generator' in str(val), ( "Unexpected: %s" % val) else:
def test_generated_raises_exception_in_teardown(self): self.fxt.loader = AbusiveMockLoader() @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) @raises(Exception) def run_tests(): SilentTestRunner().run(suite) run_tests() eq_(mock_call_log[0], (AbusiveMockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0))
def test_generated_raises_exception_in_teardown(self): self.fxt.loader = AbusiveMockLoader() @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) @raises(Exception) def run_tests(): SilentTestRunner().run(suite) run_tests() eq_(mock_call_log[0], (AbusiveMockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0))
def test_generated_tests_call_teardown_on_error(self): @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): @raises(RuntimeError) def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) raise RuntimeError for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) SilentTestRunner().run(suite) eq_(mock_call_log[0], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0)) eq_(mock_call_log[2], (MockLoader, 'unload')) eq_(mock_call_log[3], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[4], ('some_generator', Fixture.Data, 1)) eq_(mock_call_log[5], (MockLoader, 'unload'))
def test_generated_tests_call_teardown_on_error(self): @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): @raises(RuntimeError) def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) raise RuntimeError for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) SilentTestRunner().run(suite) eq_(mock_call_log[0], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0)) eq_(mock_call_log[2], (MockLoader, 'unload')) eq_(mock_call_log[3], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[4], ('some_generator', Fixture.Data, 1)) eq_(mock_call_log[5], (MockLoader, 'unload'))
def test_generated_error_raises_soft_exception_in_teardown(self): self.fxt.loader = AbusiveMockLoader() @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) raise RuntimeError("error raised from some_generator") for step in range(2): yield generated_test, step loader = nose.loader.TestLoader() loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) @raises(RuntimeError) def run_tests(): SilentTestRunner().run(suite) err = StringIO() sys.stderr = err try: try: run_tests() except Exception: etype, val, tb = sys.exc_info() assert 'error raised from some_generator' in str(val), ( "Unexpected: %s" % val) else: assert False, "expected an exception to be raised" finally: sys.stderr = sys.__stderr__ saved_err = err.getvalue() assert "ValueError: An exception during teardown" in \ saved_err, ( "unexpected stderr capture: \n<<<<<<\n%s>>>>>>\n" % saved_err) eq_(mock_call_log[0], (AbusiveMockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0))
def test_with_data_decorates_a_generator(self): @self.fxt.with_data(StubDataset1, StubDataset2) def some_generator(): def generated_test(data, step): mock_call_log.append(('some_generator', data.__class__, step)) for step in range(4): yield generated_test, step loader = nose.loader.TestLoader() # 0.10 only .... suite = loader.loadTestsFromGenerator(some_generator, None) SilentTestRunner().run(suite) eq_(mock_call_log[0], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[1], ('some_generator', Fixture.Data, 0)) eq_(mock_call_log[2], (MockLoader, 'unload')) eq_(mock_call_log[3], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[4], ('some_generator', Fixture.Data, 1)) eq_(mock_call_log[5], (MockLoader, 'unload')) eq_(mock_call_log[6], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[7], ('some_generator', Fixture.Data, 2)) eq_(mock_call_log[8], (MockLoader, 'unload')) eq_(mock_call_log[9], (MockLoader, 'load', StubSuperSet)) eq_(mock_call_log[10], ('some_generator', Fixture.Data, 3))