Skip to content

Commit c0d8f5f

Browse files
committed
[py] Ignore exception in no_driver_after_test fixture
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.
1 parent a61dff1 commit c0d8f5f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

py/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import pytest
2424

2525
from selenium import webdriver
26+
from selenium.common.exceptions import WebDriverException
2627
from selenium.webdriver.remote.server import Server
2728
from test.selenium.webdriver.common.network import get_lan_ip
2829
from test.selenium.webdriver.common.webserver import SimpleWebServer
@@ -350,8 +351,13 @@ def driver(request):
350351

351352
if request.node.get_closest_marker("no_driver_after_test"):
352353
if selenium_driver is not None:
353-
selenium_driver.stop_driver()
354-
selenium_driver = None
354+
try:
355+
selenium_driver.stop_driver()
356+
except WebDriverException:
357+
pass
358+
except Exception:
359+
raise
360+
selenium_driver = None
355361

356362

357363
@pytest.fixture(scope="session", autouse=True)

0 commit comments

Comments
 (0)