def test_proxy_calls_plugins(self): from nose.case import Test res = unittest.TestResult() class TC(unittest.TestCase): def test_error(self): print "So long" raise TypeError("oops") def test_fail(self): print "Hello" self.fail() def test(self): pass plugs = RecordingPluginManager() config = Config(plugins=plugs) factory = ResultProxyFactory(config=config) case_e = Test(TC('test_error')) case_f = Test(TC('test_fail')) case_t = Test(TC('test')) pres_e = factory(res, case_e) case_e(pres_e) assert 'beforeTest' in plugs.called assert 'startTest' in plugs.called assert 'addError' in plugs.called assert 'stopTest' in plugs.called assert 'afterTest' in plugs.called plugs.reset() pres_f = factory(res, case_f) case_f(pres_f) assert 'beforeTest' in plugs.called assert 'startTest' in plugs.called assert 'addFailure' in plugs.called assert 'stopTest' in plugs.called assert 'afterTest' in plugs.called plugs.reset() pres_t = factory(res, case_t) case_t(pres_t) assert 'beforeTest' in plugs.called assert 'startTest' in plugs.called assert 'addSuccess' in plugs.called assert 'stopTest' in plugs.called assert 'afterTest' in plugs.called plugs.reset()
def __init__(self, config=None, suiteClass=None, resultProxy=_def): if config is None: config = Config() self.config = config if suiteClass is not None: self.suiteClass = suiteClass # Using a singleton to represent default instead of None allows # passing resultProxy=None to turn proxying off. if resultProxy is _def: resultProxy = ResultProxyFactory(config=config) self.resultProxy = resultProxy self.suites = {} self.context = {} self.was_setup = {} self.was_torndown = {}
def test_skip_prevents_pdb_call(self): class TC(unittest.TestCase): def test(self): raise SkipTest('not me') skip = Skip() skip.enabled = True p = debug.Pdb() p.enabled = True p.enabled_for_errors = True res = unittest.TestResult() conf = Config(plugins=PluginManager(plugins=[skip, p])) rpf = ResultProxyFactory(conf) test = case.Test(TC('test'), resultProxy=rpf) test(res) assert not res.errors, "Skip was recorded as error %s" % res.errors assert not debug.pdb.called, "pdb was called"
def __init__(self, *args, **kwargs): super(TestLoader, self).__init__(*args, **kwargs) self.suiteClass = ContextSuiteFactory( self.config, resultProxy=ResultProxyFactory(config=self.config))