PyDev unittesting: How to capture text logged to a logging.Logger in “Captured Output”

后端 未结 7 2149
青春惊慌失措
青春惊慌失措 2020-12-07 20:08

I am using PyDev for development and unit-testing of my Python application. As for unit-testing, everything works great except the fact that no content is logged to the logg

7条回答
  •  一向
    一向 (楼主)
    2020-12-07 20:31

    This is a small hack but it works for me. Add this code when you want to display captured logs. Remove it after no needed.

    self.assertEqual(1, 0)
    

    Example:

    def test_test_awesome_function():
        print("Test 1")
        logging.info("Test 2")
        logging.warning("Test 3")
    
        self.assertEqual(1, 0)
    

提交回复
热议问题