-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193) #93193
Conversation
Teardown after test_taskName.
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
logging.logAsyncioTasks = False | ||
runner.run(log_record(self.assertIsNone)) | ||
finally: | ||
asyncio.set_event_loop_policy(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tearing down, else we end up with:
== Tests result: SUCCESS ==
406 tests OK.
1 test altered the execution environment:
test_logging
29 tests skipped:
test_curses test_dbm_gnu test_devpoll test_epoll test_gdb
test_idle test_ioctl test_launcher test_msilib
test_multiprocessing_fork test_ossaudiodev test_smtpnet
test_socketserver test_spwd test_ssl test_startfile test_tcl
test_tix test_tk test_ttk_guionly test_ttk_textonly test_turtle
test_urllib2net test_urllibnet test_winconsoleio test_winreg
test_winsound test_xmlrpc_net test_zipfile64
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Minor refactor in LogRecord.__init__ as per suggestions. Fixed typo in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one suggested minor change, and one question.
Lib/test/test_logging.py
Outdated
with open('test.log', encoding='utf-8') as f: | ||
data = f.read().strip() | ||
os.remove('test.log') | ||
self.assertEqual('Task-1 - hello world', data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we be sure the task name will always be Task-1
? What if more asyncio tasks are added in other tests which run before this one? Will the numbering still start at 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have changed it to an assertRegex
, similar to:
cpython/Lib/test/test_asyncio/test_tasks.py
Lines 393 to 394 in 1f134e9
match1 = re.match(r"^<Task pending name='Task-(\d+)'", repr(t1)) | |
self.assertIsNotNone(match1) |
Misc/NEWS.d/next/Library/2022-05-25-00-21-28.gh-issue-91513.9VyCT4.rst
Outdated
Show resolved
Hide resolved
…istent. Removed percent styling from News entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Azure pipeline check is failing - this is usually due to whitespace normalization issues. Can you please run make patchcheck
and fixup anything that's found?
Pipelines looking green after pulling most recent main branch. |
with open('test.log', encoding='utf-8') as f: | ||
data = f.read().strip() | ||
os.remove('test.log') | ||
self.assertRegex(data, r'Task-\d+ - hello world') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handler = None
try:
...
finally:
asyncio.set_event_loop_policy(None)
if handler is not None:
handler.close()
if os.path.exists('test.log'):
....
to prevent sub-exceptions in the finally block if there is an exception/assertion error in the try block ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have put the self.assertRegex(data, r'Task-\d+ - hello world')
at the end of the try block too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a fair point. This test probably needs tidying up a little.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the pattern of the encoding tests above this one.
Happy to raise a new PR and fix it up along with the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK, I've just done it. I'm working on logging tests for something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's #93265.
For: #91513
Continuing on from carlbordum@6e7dc2c 😃
Can test using: