MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_log_taskName

Method test_log_taskName

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

Source from the content-addressed store, hash-verified

5658
5659 @support.requires_working_socket()
5660 def test_log_taskName(self):
5661 async def log_record():
5662 logging.warning('hello world')
5663
5664 handler = None
5665 log_filename = make_temp_file('.log', 'test-logging-taskname-')
5666 self.addCleanup(os.remove, log_filename)
5667 try:
5668 encoding = 'utf-8'
5669 logging.basicConfig(filename=log_filename, errors='strict',
5670 encoding=encoding, level=logging.WARNING,
5671 format='%(taskName)s - %(message)s')
5672
5673 self.assertEqual(len(logging.root.handlers), 1)
5674 handler = logging.root.handlers[0]
5675 self.assertIsInstance(handler, logging.FileHandler)
5676
5677 with asyncio.Runner(debug=True) as runner:
5678 logging.logAsyncioTasks = True
5679 runner.run(log_record())
5680 with open(log_filename, encoding='utf-8') as f:
5681 data = f.read().strip()
5682 self.assertRegex(data, r'Task-\d+ - hello world')
5683 finally:
5684 asyncio.set_event_loop_policy(None)
5685 if handler:
5686 handler.close()
5687
5688
5689 def _test_log(self, method, level=None):

Callers

nothing calls this directly

Calls 11

make_temp_fileFunction · 0.85
lenFunction · 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