Skip to content
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

[py] improve driver logging #12103

Merged
merged 3 commits into from
Jun 15, 2023
Merged

[py] improve driver logging #12103

merged 3 commits into from
Jun 15, 2023

Conversation

titusfortner
Copy link
Member

@titusfortner titusfortner commented May 27, 2023

Description

  • Deprecate the current log_file or log_path Service class constructor parameters, which only accepts strings as filenames
  • Create new log_output (which matches Java's withLogOutput()) constructor parameter. This parameter that accepts:
  • Default for Firefox is now null output instead of geckodriver.log ([🚀 Feature]: Default All Driver Log Output to dev/null #12016)
  • If log file selected, Chromium and IE now pipe the whole process output to a file rather than using driver argument (this matches what Java and Ruby do, and captures all driver related output which is nice)
    • EXCEPT - if --append-log or --readable-timestamp are passed (chromium) because those only work with log-file driver argument
  • Safari - quiet parameter does not do anything in Apple's driver; it was never removed from prior implementation

Motivation and Context

Make things consistent between drivers and with Java & Ruby

One thing I'm not sure of....
This currently deprecates and warns about the change in default Firefox behavior; I think I'd prefer just changing it and maybe logging a message about the change with a link to the docs (https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output)

Also, I'm not sure I have the typing exactly right? I'm not sure what typing.IO[typing.Any] actually includes.

@titusfortner titusfortner added this to the 4.11 milestone May 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 27, 2023

Codecov Report

Patch coverage: 96.72% and project coverage change: +0.32 🎉

Comparison is base (7cfd137) 56.56% compared to head (01b90d2) 56.89%.

❗ Current head 01b90d2 differs from pull request most recent head 7ef54af. Consider uploading reports for the commit 7ef54af to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #12103      +/-   ##
==========================================
+ Coverage   56.56%   56.89%   +0.32%     
==========================================
  Files          86       86              
  Lines        5450     5494      +44     
  Branches      223      223              
==========================================
+ Hits         3083     3126      +43     
- Misses       2144     2145       +1     
  Partials      223      223              
Impacted Files Coverage Δ
py/selenium/types.py 75.00% <0.00%> (ø)
py/selenium/webdriver/common/service.py 89.92% <94.11%> (+0.09%) ⬆️
py/selenium/webdriver/chrome/service.py 85.71% <100.00%> (+2.38%) ⬆️
py/selenium/webdriver/chromium/service.py 90.90% <100.00%> (+5.90%) ⬆️
py/selenium/webdriver/edge/service.py 90.00% <100.00%> (+1.11%) ⬆️
py/selenium/webdriver/firefox/service.py 91.66% <100.00%> (+3.20%) ⬆️
py/selenium/webdriver/ie/service.py 90.00% <100.00%> (+2.00%) ⬆️
py/selenium/webdriver/safari/service.py 73.68% <100.00%> (-0.68%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @titusfortner!

@diemol diemol merged commit ab6e4f8 into trunk Jun 15, 2023
@diemol diemol deleted the py_driver_logs branch June 15, 2023 09:14
@vringar
Copy link

vringar commented Jun 15, 2023

Thanks for implementing this!
As this got merged in the 4.11 merge window, will it get released on July 21? And are there any beta/preview/nightly artifacts published somewhere to use this immediately?

@titusfortner
Copy link
Member Author

@vringar take a look at #12207

Comment on lines +61 to +66
if isinstance(log_output, str):
self.log_output = open(log_output, "a+", encoding="utf-8")
elif log_output is subprocess.STDOUT:
self.log_output = None
elif log_output is None or log_output is subprocess.DEVNULL:
self.log_output = open(os.devnull, "wb")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these file descriptors are never closed leading to ResourceWarnings when this is garbage collected (and leaked fds)

titusfortner pushed a commit that referenced this pull request Nov 17, 2023
* don't leak a file descriptor to os.devnull by default

since this is passed along to subprocess directly we can use the subprocess constants still

regression in #12103

* adjust condition for closing as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants