Exemple #1
0
    def test_set_up_tear_down(self):
        """
        This test makes sure that AsyncTestCase calls super methods for
        setUp and tearDown.

        InheritBoth is a subclass of both AsyncTestCase and
        SetUpTearDown, with the ordering so that the super of
        AsyncTestCase will be SetUpTearDown.
        """
        events = []
        result = unittest.TestResult()

        class SetUpTearDown(unittest.TestCase):
            def setUp(self):
                events.append('setUp')

            def tearDown(self):
                events.append('tearDown')

        class InheritBoth(AsyncTestCase, SetUpTearDown):
            def test(self):
                events.append('test')

        InheritBoth('test').run(result)
        expected = ['setUp', 'test', 'tearDown']
        self.assertEqual(expected, events)
Exemple #2
0
 def test_other_return(self):
     class Test(AsyncTestCase):
         def test_other_return(self):
             return 42
     test = Test('test_other_return')
     result = unittest.TestResult()
     test.run(result)
     self.assertEqual(len(result.errors), 1)
     self.assertIn("Return value from test method ignored", result.errors[0][1])
Exemple #3
0
 def test_undecorated_generator(self):
     class Test(AsyncTestCase):
         def test_gen(self):
             yield
     test = Test('test_gen')
     result = unittest.TestResult()
     test.run(result)
     self.assertEqual(len(result.errors), 1)
     self.assertIn("should be decorated", result.errors[0][1])
Exemple #4
0
 def test_undecorated_generator_with_skip(self):
     class Test(AsyncTestCase):
         @unittest.skip("don't run this")
         def test_gen(self):
             yield
     test = Test('test_gen')
     result = unittest.TestResult()
     test.run(result)
     self.assertEqual(len(result.errors), 0)
     self.assertEqual(len(result.skipped), 1)
Exemple #5
0
    def test_undecorated_coroutine(self):
        namespace = exec_test(globals(), locals(), """
        class Test(AsyncTestCase):
            async def test_coro(self):
                pass
        """)

        test_class = namespace['Test']
        test = test_class('test_coro')
        result = unittest.TestResult()

        # Silence "RuntimeWarning: coroutine 'test_coro' was never awaited".
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            test.run(result)

        self.assertEqual(len(result.errors), 1)
        self.assertIn("should be decorated", result.errors[0][1])