MCPcopy Index your code
hub / github.com/python/cpython / test_log_taskName

Method test_log_taskName

Lib/test/test_logging.py:5771–5797  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5769
5770 @support.requires_working_socket()
5771 def test_log_taskName(self):
5772 async def log_record():
5773 logging.warning('hello world')
5774
5775 handler = None
5776 log_filename = make_temp_file('.log', 'test-logging-taskname-')
5777 self.addCleanup(os.remove, log_filename)
5778 try:
5779 encoding = 'utf-8'
5780 logging.basicConfig(filename=log_filename, errors='strict',
5781 encoding=encoding, level=logging.WARNING,
5782 format='%(taskName)s - %(message)s')
5783
5784 self.assertEqual(len(logging.root.handlers), 1)
5785 handler = logging.root.handlers[0]
5786 self.assertIsInstance(handler, logging.FileHandler)
5787
5788 with asyncio.Runner(debug=True) as runner:
5789 logging.logAsyncioTasks = True
5790 runner.run(log_record())
5791 with open(log_filename, encoding='utf-8') as f:
5792 data = f.read().strip()
5793 self.assertRegex(data, r'Task-\d+ - hello world')
5794 finally:
5795 asyncio.events._set_event_loop_policy(None)
5796 if handler:
5797 handler.close()
5798
5799
5800 def _test_log(self, method, level=None):

Callers

nothing calls this directly

Calls 10

make_temp_fileFunction · 0.85
addCleanupMethod · 0.80
assertIsInstanceMethod · 0.80
assertRegexMethod · 0.80
openFunction · 0.50
assertEqualMethod · 0.45
runMethod · 0.45
stripMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected