From a3812fad9b3177dcd0d60980136ee845c0c20fdc Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Fri, 6 Dec 2024 03:17:12 -0300 Subject: [PATCH] [py] Avoid os.getenv error if driver_path_env_key is not set Follow up to PR #14528, to avoid `os.getenv` raising `TypeError` in `env_path` when `driver_path_env_key` is not passed to `Service` constructor. --- py/selenium/webdriver/common/service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 7d64d1826bcd6..9c592ba75a525 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -50,6 +50,7 @@ class Service(ABC): :param port: Port for the service to run on, defaults to 0 where the operating system will decide. :param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. + :param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable. """ def __init__( @@ -245,4 +246,6 @@ def _start_process(self, path: str) -> None: raise def env_path(self) -> Optional[str]: - return os.getenv(self.DRIVER_PATH_ENV_KEY, None) + if self.DRIVER_PATH_ENV_KEY: + return os.getenv(self.DRIVER_PATH_ENV_KEY, None) + return None