Python unittest.TestCase.run() Examples
The following are 30
code examples of unittest.TestCase.run().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest.TestCase
, or try the search function
.
Example #1
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_failureException__subclassing__explicit_raise(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def test(self): raise RuntimeError() failureException = RuntimeError self.failUnless(Foo('test').failureException is RuntimeError) Foo('test').run(result) expected = ['startTest', 'addFailure', 'stopTest'] self.assertEqual(events, expected) # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in # order to ``play fair'' with the framework." # # Make sure TestCase.run() respects the designated failureException
Example #2
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_run(self): events = [] result = LoggingResult(events) class LoggingCase(unittest.TestCase): def run(self, result): events.append('run %s' % self._testMethodName) def test1(self): pass def test2(self): pass tests = [LoggingCase('test1'), LoggingCase('test2')] unittest.TestSuite(tests).run(result) self.assertEqual(events, ['run test1', 'run test2']) # "Add a TestCase ... to the suite"
Example #3
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_run(self): events = [] result = LoggingResult(events) class LoggingCase(unittest.TestCase): def run(self, result): events.append('run %s' % self._testMethodName) def test1(self): pass def test2(self): pass tests = [LoggingCase('test1'), LoggingCase('test2')] unittest.TestSuite(tests).run(result) self.assertEqual(events, ['run test1', 'run test2']) # "Add a TestCase ... to the suite"
Example #4
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_tearDown(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def setUp(self): events.append('setUp') def test(self): events.append('test') def tearDown(self): events.append('tearDown') raise RuntimeError('raised by Foo.tearDown') Foo('test').run(result) expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError', 'stopTest'] self.assertEqual(events, expected) # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in # order to ``play fair'' with the framework. The initial value of this # attribute is AssertionError"
Example #5
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_setUp(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') raise RuntimeError('raised by setUp') def test(): events.append('test') def tearDown(): events.append('tearDown') expected = ['startTest', 'setUp', 'addError', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if the test raises # an error (as opposed to a failure).
Example #6
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_failureException__subclassing__explicit_raise(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def test(self): raise RuntimeError() failureException = RuntimeError self.failUnless(Foo('test').failureException is RuntimeError) Foo('test').run(result) expected = ['startTest', 'addFailure', 'stopTest'] self.assertEqual(events, expected) # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in # order to ``play fair'' with the framework." # # Make sure TestCase.run() respects the designated failureException
Example #7
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_tearDown(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') def test(): events.append('test') def tearDown(): events.append('tearDown') raise RuntimeError('raised by tearDown') expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "Return a string identifying the specific test case." # # Because of the vague nature of the docs, I'm not going to lock this # test down too much. Really all that can be asserted is that the id() # will be a string (either 8-byte or unicode -- again, because the docs # just say "string")
Example #8
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_tearDown(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def setUp(self): events.append('setUp') def test(self): events.append('test') def tearDown(self): events.append('tearDown') raise RuntimeError('raised by Foo.tearDown') Foo('test').run(result) expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError', 'stopTest'] self.assertEqual(events, expected) # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in # order to ``play fair'' with the framework. The initial value of this # attribute is AssertionError"
Example #9
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_setUp(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') raise RuntimeError('raised by setUp') def test(): events.append('test') def tearDown(): events.append('tearDown') expected = ['startTest', 'setUp', 'addError', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if the test raises # an error (as opposed to a failure).
Example #10
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_run_call_order__error_in_tearDown(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') def test(): events.append('test') def tearDown(): events.append('tearDown') raise RuntimeError('raised by tearDown') expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "Return a string identifying the specific test case." # # Because of the vague nature of the docs, I'm not going to lock this # test down too much. Really all that can be asserted is that the id() # will be a string (either 8-byte or unicode -- again, because the docs # just say "string")
Example #11
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_init__test_name__valid(self): class Test(unittest.TestCase): def runTest(self): raise MyException() def test(self): pass self.assertEqual(Test('test').id()[-10:], '.Test.test') # "class TestCase([methodName])" # ... # "Each instance of TestCase will run a single test method: the # method named methodName."
Example #12
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_run__requires_result(self): suite = unittest.TestSuite() try: suite.run() except TypeError: pass else: self.fail("Failed to raise TypeError") # "Run the tests associated with this suite, collecting the result into # the test result object passed as result."
Example #13
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_countTestCases(self): test = unittest.FunctionTestCase(lambda: None) self.assertEqual(test.countTestCases(), 1) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if setUp() raises # an exception.
Example #14
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_run_call_order__failure_in_test(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') def test(): events.append('test') self.fail('raised by test') def tearDown(): events.append('tearDown') expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if tearDown() raises # an exception.
Example #15
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_init(self): result = unittest.TestResult() self.failUnless(result.wasSuccessful()) self.assertEqual(len(result.errors), 0) self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 0) self.assertEqual(result.shouldStop, False) # "This method can be called to signal that the set of tests being # run should be aborted by setting the TestResult's shouldStop # attribute to True."
Example #16
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_stop(self): result = unittest.TestResult() result.stop() self.assertEqual(result.shouldStop, True) # "Called when the test case test is about to be run. The default # implementation simply increments the instance's testsRun counter."
Example #17
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_init__no_test_name(self): class Test(unittest.TestCase): def runTest(self): raise MyException() def test(self): pass self.assertEqual(Test().id()[-13:], '.Test.runTest') # "class TestCase([methodName])" # ... # "Each instance of TestCase will run a single test method: the # method named methodName."
Example #18
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_run__uses_defaultTestResult(self): events = [] class Foo(unittest.TestCase): def test(self): events.append('test') def defaultTestResult(self): return LoggingResult(events) # Make run() find a result object on its own Foo('test').run() expected = ['startTest', 'test', 'stopTest'] self.assertEqual(events, expected)
Example #19
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_countTestCases(self): class Foo(unittest.TestCase): def test(self): pass self.assertEqual(Foo('test').countTestCases(), 1) # "Return the default type of test result object to be used to run this # test. For TestCase instances, this will always be # unittest.TestResult; subclasses of TestCase should # override this as necessary."
Example #20
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_defaultTestResult(self): class Foo(unittest.TestCase): def runTest(self): pass result = Foo().defaultTestResult() self.assertEqual(type(result), unittest.TestResult) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if setUp() raises # an exception.
Example #21
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_run_call_order__error_in_test(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def setUp(self): events.append('setUp') def test(self): events.append('test') raise RuntimeError('raised by Foo.test') def tearDown(self): events.append('tearDown') expected = ['startTest', 'setUp', 'test', 'addError', 'tearDown', 'stopTest'] Foo('test').run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if the test signals # a failure (as opposed to an error).
Example #22
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_run_call_order__failure_in_test(self): events = [] result = LoggingResult(events) class Foo(unittest.TestCase): def setUp(self): events.append('setUp') def test(self): events.append('test') self.fail('raised by Foo.test') def tearDown(self): events.append('tearDown') expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown', 'stopTest'] Foo('test').run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if tearDown() raises # an exception.
Example #23
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_failureException__default(self): class Foo(unittest.TestCase): def test(self): pass self.failUnless(Foo('test').failureException is AssertionError) # "This class attribute gives the exception raised by the test() method. # If a test framework needs to use a specialized exception, possibly to # carry additional information, it must subclass this exception in # order to ``play fair'' with the framework." # # Make sure TestCase.run() respects the designated failureException
Example #24
Source File: test_unittest.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_run__uses_defaultTestResult(self): events = [] class Foo(unittest.TestCase): def test(self): events.append('test') def defaultTestResult(self): return LoggingResult(events) # Make run() find a result object on its own Foo('test').run() expected = ['startTest', 'test', 'stopTest'] self.assertEqual(events, expected)
Example #25
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_init__no_test_name(self): class Test(unittest.TestCase): def runTest(self): raise MyException() def test(self): pass self.assertEqual(Test().id()[-13:], '.Test.runTest') # "class TestCase([methodName])" # ... # "Each instance of TestCase will run a single test method: the # method named methodName."
Example #26
Source File: QATdx_Test_multi_process_map.py From QUANTAXIS with MIT License | 5 votes |
def test_gen_param(self): codelist = QA.QA_fetch_stock_list_adv().code.tolist() days = 300 start = datetime.datetime.now().date() - datetime.timedelta(days) end = datetime.datetime.now().date() - datetime.timedelta(10) codeListCount = 200 ips = get_ip_list_by_multi_process_ping(QA.QAUtil.stock_ip_list, _type='stock') param = gen_param(codelist[:codeListCount], start, end, IPList=ips[:cpu_count()]) a = time.time() ps = Parallelism(cpu_count()) ps.run(QA.QAFetch.QATdx.QA_fetch_get_stock_day, param) data = ps.get_results() b = time.time() t1 = b - a data = list(data) print('返回数据{}条,用时:{}秒'.format(len(data), t1)) # print(data) # print([x.code.unique() for x in data]) self.assertTrue(len(data) == codeListCount, '返回结果和输入参数个数不匹配: {} {}'.format(len(data), codeListCount)) i, j = 0, 0 for x in data: try: # print(x) i += 1 self.assertTrue((x is None) or (len(x) > 0), '返回数据太少:{}'.format(len(x))) if not ((x is None) or (len(x) > 0)): print('data is None') if i % 10 == 0: print(x) except Exception as e: j += 1 print(i, j)
Example #27
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_run__empty_suite(self): events = [] result = LoggingResult(events) suite = unittest.TestSuite() suite.run(result) self.assertEqual(events, []) # "Note that unlike TestCase.run(), TestSuite.run() requires the # "result object to be passed in."
Example #28
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_run__requires_result(self): suite = unittest.TestSuite() try: suite.run() except TypeError: pass else: self.fail("Failed to raise TypeError") # "Run the tests associated with this suite, collecting the result into # the test result object passed as result."
Example #29
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_countTestCases(self): test = unittest.FunctionTestCase(lambda: None) self.assertEqual(test.countTestCases(), 1) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if setUp() raises # an exception.
Example #30
Source File: test_unittest.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_run_call_order__failure_in_test(self): events = [] result = LoggingResult(events) def setUp(): events.append('setUp') def test(): events.append('test') self.fail('raised by test') def tearDown(): events.append('tearDown') expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown', 'stopTest'] unittest.FunctionTestCase(test, setUp, tearDown).run(result) self.assertEqual(events, expected) # "When a setUp() method is defined, the test runner will run that method # prior to each test. Likewise, if a tearDown() method is defined, the # test runner will invoke that method after each test. In the example, # setUp() was used to create a fresh sequence for each test." # # Make sure the proper call order is maintained, even if tearDown() raises # an exception.