-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] Remove redundant driver_instance from conftest.py #16271
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] Remove redundant driver_instance from conftest.py #16271
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
ccae768 to
59d4ba9
Compare
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
|
Thanks @lauromoura |
|
This is causing a failure in CI. https://github.com/SeleniumHQ/selenium/actions/runs/17329416928/job/49202234767?pr=16271 |
Checking it. Thanks for the heads-up. |
Currently, the driver lifetime is handled by two global variables: - `driver_instance`, the actual Selenium API driver. - `selenium_driver`, the wrapper `conftest.Driver`, which "owns" the former. Also, conftest.py could quit the driver from multiple places: - `Driver.stop_driver` finalizer, used for bidi and xfail tests - `stop_driver` Session-scope fixture finalizer - `pytest_exception_interact` to handle exceptions The last two paths called `driver_instance.quit()` directly but did not tell `selenium_driver` that the driver had exited. This could potentially raise `urllib.exception.MaxRetryError`, as `Driver.stop_driver` would try to send the `quit()` command to an already destroyed driver service. For example, this happened rather frequently on WebKit import of selenium 4.34.2 tests, whenever an exception happened, as we have enabled the `bidi` flag when calling pytest. To address this issue, this commit removes the global variable `driver_instance`, keeping only `selenium_driver` as global, and routes all teardown paths through `Driver.stop_driver()`.
As suggested by the review bot
The `no_driver_after_test` indicates that tests are expected to quit the driver themselves, leaving `selenium_driver` with a stale driver instance. This commit keeps the `stop_driver()` call as a safety fallback, but ignores WebDriverExceptions since they're expected in the call when the test properly quits the driver.
7edce65 to
c0d8f5f
Compare
|
@cgoldberg CI fixed :) |
cgoldberg
left a comment
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.
LGTM. Thanks @lauromoura
…rors on test failure https://bugs.webkit.org/show_bug.cgi?id=296255 Reviewed by NOBODY (OOPS!). Includes the fix upstreamed in SeleniumHQ/selenium#16271 This reduces the amount of MaxRetryErrors from 61 to 4, which now are related to ungardened tests. * WebDriverTests/imported/selenium/importer.json: Updated hash * WebDriverTests/imported/selenium/: Updated the selenium copy, with the usual skip of Chrome, Edge, and Firefox related code.
…rors on test failure https://bugs.webkit.org/show_bug.cgi?id=296255 Reviewed by NOBODY (OOPS!). Includes the fix upstreamed in SeleniumHQ/selenium#16271 This reduces the amount of MaxRetryErrors from 61 to 4, which now are related to ungardened tests. * WebDriverTests/imported/selenium/importer.json: Updated hash * WebDriverTests/imported/selenium/: Updated the selenium copy, with the usual skip of Chrome, Edge, and Firefox related code.
…rors on test failure https://bugs.webkit.org/show_bug.cgi?id=296255 Reviewed by BJ Burg. Includes the fix upstreamed in SeleniumHQ/selenium#16271 This reduces the amount of MaxRetryErrors from 61 to 4, which now are related to ungardened tests. * WebDriverTests/imported/selenium/importer.json: Updated hash * WebDriverTests/imported/selenium/: Updated the selenium copy, with the usual skip of Chrome, Edge, and Firefox related code. Canonical link: https://commits.webkit.org/300552@main
User description
🔗 Problem description
Currently, the driver lifetime is handled by two global variables:
driver_instance, the actual Selenium API driver.selenium_driver, the wrapperconftest.Driver, which "owns" the former.Also, conftest.py could quit the driver from multiple places:
Driver.stop_driverfinalizer, used for bidi and xfail testsstop_driverSession-scope fixture finalizerpytest_exception_interactto handle exceptionsThe last two paths called
driver_instance.quit()directly but did not tellselenium_driverthat the driver had exited. This could potentially raiseurllib.exception.MaxRetryError, asDriver.stop_driverwould try to send thequit()command to an already destroyed driver service.For example, this happened rather frequently on WebKit import of selenium 4.34.2 tests, whenever an exception happened, as we have enabled the
bidiflag when calling pytest.💥 What does this PR do?
To address this issue, this commit removes the global variable
driver_instance, keeping onlyselenium_driveras global, and routes all teardown paths throughDriver.stop_driver().🔄 Types of changes
PR Type
Bug fix, Other
Description
Remove redundant
driver_instanceglobal variable from conftest.pyRoute all driver teardown paths through
Driver.stop_driver()methodFix potential
MaxRetryErrorwhen driver quit called multiple timesImprove driver lifecycle management consistency
Diagram Walkthrough
File Walkthrough
conftest.py
Consolidate driver teardown logicpy/conftest.py
driver_instancevariable declarationstop_driverfrom property to method in Driver classselenium_driver.stop_driver()selenium_driverin BiDi test cleanup