File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 3
3
from browserstack .bserrors import BrowserStackLocalError
4
4
5
5
class Local :
6
- def __init__ (self , key = None , binary_path = None ):
6
+ def __init__ (self , key = None , binary_path = None , ** kwargs ):
7
7
self .key = os .environ ['BROWSERSTACK_ACCESS_KEY' ] if 'BROWSERSTACK_ACCESS_KEY' in os .environ else key
8
- self .options = None
8
+ self .options = kwargs
9
9
self .local_logfile_path = os .path .join (os .getcwd (), 'local.log' )
10
10
11
11
def __xstr (self , key , value ):
@@ -29,7 +29,8 @@ def _generate_stop_cmd(self):
29
29
return cmd
30
30
31
31
def start (self , ** kwargs ):
32
- self .options = kwargs
32
+ for k , v in kwargs .items ():
33
+ self .options [k ] = v
33
34
34
35
if 'key' in self .options :
35
36
self .key = self .options ['key' ]
@@ -74,3 +75,10 @@ def stop(self):
74
75
(out , err ) = proc .communicate ()
75
76
except Exception as e :
76
77
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):
79
79
self .local .start (localIdentifier = 'mytunnel' , onlyCommand = True )
80
80
self .assertIn ('-localIdentifier' , self .local ._generate_cmd ())
81
81
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