2525from  platform  import  system 
2626from  subprocess  import  PIPE 
2727from  time  import  sleep 
28+ from  typing  import  Optional 
2829from  typing  import  cast 
2930from  urllib  import  request 
3031from  urllib .error  import  URLError 
@@ -53,6 +54,7 @@ def __init__(
5354        port : int  =  0 ,
5455        log_output : SubprocessStdAlias  =  None ,
5556        env : typing .Optional [typing .Mapping [typing .Any , typing .Any ]] =  None ,
57+         driver_path_env_key : str  =  None ,
5658        ** kwargs ,
5759    ) ->  None :
5860        if  isinstance (log_output , str ):
@@ -64,12 +66,13 @@ def __init__(
6466        else :
6567            self .log_output  =  log_output 
6668
67-         self ._path  =  executable_path 
6869        self .port  =  port  or  utils .free_port ()
6970        # Default value for every python subprocess: subprocess.Popen(..., creationflags=0) 
7071        self .popen_kw  =  kwargs .pop ("popen_kw" , {})
7172        self .creation_flags  =  self .popen_kw .pop ("creation_flags" , 0 )
7273        self .env  =  env  or  os .environ 
74+         self .DRIVER_PATH_ENV_KEY  =  driver_path_env_key 
75+         self ._path  =  self .env_path () or  executable_path 
7376
7477    @property  
7578    def  service_url (self ) ->  str :
@@ -236,3 +239,6 @@ def _start_process(self, path: str) -> None:
236239                    f"'{ os .path .basename (self ._path )}  ' executable may have wrong permissions." 
237240                ) from  err 
238241            raise 
242+ 
243+     def  env_path (self ) ->  Optional [str ]:
244+         return  os .getenv (self .DRIVER_PATH_ENV_KEY , None )
0 commit comments