File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from browserstack .bserrors import BrowserStackLocalError
44
55class Local :
6- def __init__ (self , key = None , binary_path = None ):
6+ def __init__ (self , key = None , binary_path = None , ** kwargs ):
77 self .key = os .environ ['BROWSERSTACK_ACCESS_KEY' ] if 'BROWSERSTACK_ACCESS_KEY' in os .environ else key
8- self .options = None
8+ self .options = kwargs
99 self .local_logfile_path = os .path .join (os .getcwd (), 'local.log' )
1010
1111 def __xstr (self , key , value ):
@@ -29,7 +29,8 @@ def _generate_stop_cmd(self):
2929 return cmd
3030
3131 def start (self , ** kwargs ):
32- self .options = kwargs
32+ for k , v in kwargs .items ():
33+ self .options [k ] = v
3334
3435 if 'key' in self .options :
3536 self .key = self .options ['key' ]
@@ -74,3 +75,10 @@ def stop(self):
7475 (out , err ) = proc .communicate ()
7576 except Exception as e :
7677 return
78+
79+ def __enter__ (self ):
80+ self .start (** self .options )
81+ return self
82+
83+ def __exit__ (self , * args ):
84+ self .stop ()
Original file line number Diff line number Diff line change @@ -79,3 +79,7 @@ def test_local_identifier(self):
7979 self .local .start (localIdentifier = 'mytunnel' , onlyCommand = True )
8080 self .assertIn ('-localIdentifier' , self .local ._generate_cmd ())
8181 self .assertIn ('mytunnel' , self .local ._generate_cmd ())
82+
83+ def test_context_manager (self ):
84+ with Local ('BROWSERSTACK_ACCESS_KEY' ) as local :
85+ self .assertNotEqual (local .proc .pid , 0 )
You can’t perform that action at this time.
0 commit comments