def testNoExit(self): result = object() test = object() class FakeRunner(object): def run(self, test): self.test = test return result runner = FakeRunner() oldParseArgs = unittest2.TestProgram.parseArgs def restoreParseArgs(): unittest2.TestProgram.parseArgs = oldParseArgs unittest2.TestProgram.parseArgs = lambda *args: None self.addCleanup(restoreParseArgs) def removeTest(): del unittest2.TestProgram.test unittest2.TestProgram.test = test self.addCleanup(removeTest) program = unittest2.TestProgram( testRunner=runner, exit=False, verbosity=2) self.assertEqual(program.result, result) self.assertEqual(runner.test, test) self.assertEqual(program.verbosity, 2)
def main(imports=None): if imports: global suite suite = suite(imports) defaultTest = 'fixture.suite' else: defaultTest = None return unittest2.TestProgram(defaultTest=defaultTest)
def test_defaultTest_with_string(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram(testRunner=runner, exit=False, defaultTest='unittest.test', testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(('unittest.test',), program.testNames)