Python unittest.TextTestResult() Examples

The following are 30 code examples for showing how to use unittest.TextTestResult(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module unittest , or try the search function .

Example 1
Project: OpenRAM   Author: VLSIDA   File: testutils.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def debugTestRunner(post_mortem=None):
    """unittest runner doing post mortem debugging on failing tests"""
    if post_mortem is None and not OPTS.purge_temp:
        post_mortem = pdb.post_mortem
    class DebugTestResult(unittest.TextTestResult):
        def addError(self, test, err):
            # called before tearDown()
            traceback.print_exception(*err)
            if post_mortem:
                post_mortem(err[2])
            super(DebugTestResult, self).addError(test, err)
        def addFailure(self, test, err):
            traceback.print_exception(*err)
            if post_mortem:            
                post_mortem(err[2])
            super(DebugTestResult, self).addFailure(test, err)
    return unittest.TextTestRunner(resultclass=DebugTestResult) 
Example 2
Project: tellurium   Author: sys-bio   File: test_runner.py    License: Apache License 2.0 6 votes vote down vote up
def run_all():
        """ Run all unittests of tellurium.

        :return: results of unittest
        :rtype: unittest.TextTestResult
        """
        import matplotlib
        backend = matplotlib.rcParams['backend']
        matplotlib.pyplot.switch_backend("Agg")

        # get the test modules and add to test suite
        modules = TestRunner.find_test_modules()

        suites = [unittest.defaultTestLoader.loadTestsFromName(s) for s in modules]
        testSuite = unittest.TestSuite(suites)
        results = unittest.TextTestRunner(verbosity=2).run(testSuite)
        matplotlib.pyplot.switch_backend(backend)
        return results 
Example 3
Project: jawfish   Author: war-and-code   File: test_runner.py    License: MIT License 5 votes vote down vote up
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertEqual(runner.warnings, None)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult) 
Example 4
Project: jawfish   Author: war-and-code   File: testpatch.py    License: MIT License 5 votes vote down vote up
def test_tracebacks(self):
        @patch.object(Foo, 'f', object())
        def test():
            raise AssertionError
        try:
            test()
        except:
            err = sys.exc_info()

        result = unittest.TextTestResult(None, None, 0)
        traceback = result._exc_info_to_string(err, self)
        self.assertIn('raise AssertionError', traceback) 
Example 5
Project: jawfish   Author: war-and-code   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithoutDocstring(self):
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
                'testGetDescriptionWithoutDocstring (' + __name__ +
                '.Test_TestResult)') 
Example 6
Project: jawfish   Author: war-and-code   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithOneLineDocstring(self):
        """Tests getDescription() for a method with a docstring."""
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithOneLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a docstring.')) 
Example 7
Project: jawfish   Author: war-and-code   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithMultiLineDocstring(self):
        """Tests getDescription() for a method with a longer docstring.
        The second line of the docstring.
        """
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithMultiLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a longer '
                'docstring.')) 
Example 8
Project: ironpython2   Author: IronLanguages   File: test_runner.py    License: Apache License 2.0 5 votes vote down vote up
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult) 
Example 9
Project: ironpython2   Author: IronLanguages   File: test_runner.py    License: Apache License 2.0 5 votes vote down vote up
def test_multiple_inheritance(self):
        class AResult(unittest.TestResult):
            def __init__(self, stream, descriptions, verbosity):
                super(AResult, self).__init__(stream, descriptions, verbosity)

        class ATextResult(unittest.TextTestResult, AResult):
            pass

        # This used to raise an exception due to TextTestResult not passing
        # on arguments in its __init__ super call
        ATextResult(None, None, 1) 
Example 10
Project: ironpython2   Author: IronLanguages   File: test_result.py    License: Apache License 2.0 5 votes vote down vote up
def testGetDescriptionWithoutDocstring(self):
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
                'testGetDescriptionWithoutDocstring (' + __name__ +
                '.Test_TestResult)') 
Example 11
Project: ironpython2   Author: IronLanguages   File: test_result.py    License: Apache License 2.0 5 votes vote down vote up
def testGetDescriptionWithOneLineDocstring(self):
        """Tests getDescription() for a method with a docstring."""
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithOneLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a docstring.')) 
Example 12
Project: ironpython2   Author: IronLanguages   File: test_result.py    License: Apache License 2.0 5 votes vote down vote up
def testGetDescriptionWithMultiLineDocstring(self):
        """Tests getDescription() for a method with a longer docstring.
        The second line of the docstring.
        """
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithMultiLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a longer '
                'docstring.')) 
Example 13
Project: BinderFilter   Author: dxwu   File: test_runner.py    License: MIT License 5 votes vote down vote up
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult) 
Example 14
Project: BinderFilter   Author: dxwu   File: test_runner.py    License: MIT License 5 votes vote down vote up
def test_multiple_inheritance(self):
        class AResult(unittest.TestResult):
            def __init__(self, stream, descriptions, verbosity):
                super(AResult, self).__init__(stream, descriptions, verbosity)

        class ATextResult(unittest.TextTestResult, AResult):
            pass

        # This used to raise an exception due to TextTestResult not passing
        # on arguments in its __init__ super call
        ATextResult(None, None, None) 
Example 15
Project: BinderFilter   Author: dxwu   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithoutDocstring(self):
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
                'testGetDescriptionWithoutDocstring (' + __name__ +
                '.Test_TestResult)') 
Example 16
Project: BinderFilter   Author: dxwu   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithOneLineDocstring(self):
        """Tests getDescription() for a method with a docstring."""
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithOneLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a docstring.')) 
Example 17
Project: BinderFilter   Author: dxwu   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithMultiLineDocstring(self):
        """Tests getDescription() for a method with a longer docstring.
        The second line of the docstring.
        """
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithMultiLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a longer '
                'docstring.')) 
Example 18
Project: oss-ftp   Author: aliyun   File: test_runner.py    License: MIT License 5 votes vote down vote up
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult) 
Example 19
Project: oss-ftp   Author: aliyun   File: test_runner.py    License: MIT License 5 votes vote down vote up
def test_multiple_inheritance(self):
        class AResult(unittest.TestResult):
            def __init__(self, stream, descriptions, verbosity):
                super(AResult, self).__init__(stream, descriptions, verbosity)

        class ATextResult(unittest.TextTestResult, AResult):
            pass

        # This used to raise an exception due to TextTestResult not passing
        # on arguments in its __init__ super call
        ATextResult(None, None, 1) 
Example 20
Project: oss-ftp   Author: aliyun   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithoutDocstring(self):
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
                'testGetDescriptionWithoutDocstring (' + __name__ +
                '.Test_TestResult)') 
Example 21
Project: oss-ftp   Author: aliyun   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithOneLineDocstring(self):
        """Tests getDescription() for a method with a docstring."""
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithOneLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a docstring.')) 
Example 22
Project: oss-ftp   Author: aliyun   File: test_result.py    License: MIT License 5 votes vote down vote up
def testGetDescriptionWithMultiLineDocstring(self):
        """Tests getDescription() for a method with a longer docstring.
        The second line of the docstring.
        """
        result = unittest.TextTestResult(None, True, 1)
        self.assertEqual(
                result.getDescription(self),
               ('testGetDescriptionWithMultiLineDocstring '
                '(' + __name__ + '.Test_TestResult)\n'
                'Tests getDescription() for a method with a longer '
                'docstring.')) 
Example 23
Project: GYP3   Author: refack   File: taprunner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addSuccess(self, test):
        super(TextTestResult, self).addSuccess(test)
        self._process(test, "ok") 
Example 24
Project: GYP3   Author: refack   File: taprunner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addFailure(self, test, err):
        super(TextTestResult, self).addFailure(test, err)
        self._process(test, "not ok", "FAIL")
        # [ ] add structured data about assertion 
Example 25
Project: GYP3   Author: refack   File: taprunner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addError(self, test, err):
        super(TextTestResult, self).addError(test, err)
        self._process(test, "not ok", "ERROR")
        # [ ] add structured data about exception 
Example 26
Project: GYP3   Author: refack   File: taprunner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addSkip(self, test, reason):
        super(TextTestResult, self).addSkip(test, reason)
        self._process(test, "ok", directive=("  # SKIP  %s" % reason)) 
Example 27
Project: GYP3   Author: refack   File: taprunner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addExpectedFailure(self, test, err):
        super(TextTestResult, self).addExpectedFailure(test, err)
        self._process(test, "not ok", directive=("  # TODO")) 
Example 28
Project: py-ipv8   Author: Tribler   File: run_all_tests.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def addSuccess(self, test):
        super(unittest.TextTestResult, self).addSuccess(test)
        if self.showAll:
            self.stream.writeln(f"ok [{round((time.time() - self.last_test) * 1000, 2)} ms]")
        elif self.dots:
            self.stream.write('.')
            self.stream.flush() 
Example 29
Project: Fluid-Designer   Author: Microvellum   File: test_runner.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertEqual(runner.warnings, None)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult)
        self.assertFalse(runner.tb_locals) 
Example 30
Project: Fluid-Designer   Author: Microvellum   File: test_runner.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_multiple_inheritance(self):
        class AResult(unittest.TestResult):
            def __init__(self, stream, descriptions, verbosity):
                super(AResult, self).__init__(stream, descriptions, verbosity)

        class ATextResult(unittest.TextTestResult, AResult):
            pass

        # This used to raise an exception due to TextTestResult not passing
        # on arguments in its __init__ super call
        ATextResult(None, None, 1)