@@ -615,26 +615,29 @@ def test_become_dask(self):
615
615
def test_warning_on_hostname_match (self ):
616
616
location = socket .gethostname ()
617
617
with mock .patch ('ipyparallel.client.client.is_local_ip' , lambda x : False ):
618
- with mock .patch ('socket.gethostname' , lambda : location [0 :- 1 ]), pytest .warns (
619
- RuntimeWarning
620
- ): # should trigger warning
621
- c = self .connect_client ()
618
+ with mock .patch ('socket.gethostname' , lambda : location [0 :- 1 ]):
619
+ with pytest .warns (RuntimeWarning ): # should trigger warning
620
+ c = self .connect_client ()
621
+ c .close ()
622
+ with mock .patch ('socket.gethostname' , lambda : location ):
623
+ with pytest .warns (None ) as record : # should not trigger warning
624
+ c = self .connect_client ()
625
+ # only capture runtime warnings
626
+ runtime_warnings = [
627
+ w for w in record if isinstance (w .message , RuntimeWarning )
628
+ ]
629
+ assert len (runtime_warnings ) == 0 , str (
630
+ [str (w ) for w in runtime_warnings ]
631
+ )
622
632
c .close ()
623
- with mock .patch ('socket.gethostname' , lambda : location ), pytest .warns (
624
- None
625
- ) as record : # should not trigger warning
633
+
634
+ def test_local_ip_true_doesnt_trigger_warning (self ):
635
+ with mock .patch ('ipyparallel.client.client.is_local_ip' , lambda x : True ):
636
+ with pytest .warns (None ) as record :
626
637
c = self .connect_client ()
627
638
# only capture runtime warnings
628
639
runtime_warnings = [
629
640
w for w in record if isinstance (w .message , RuntimeWarning )
630
641
]
631
642
assert len (runtime_warnings ) == 0 , str ([str (w ) for w in runtime_warnings ])
632
643
c .close ()
633
-
634
- def test_local_ip_true_doesnt_trigger_warning (self ):
635
- with mock .patch (
636
- 'ipyparallel.client.client.is_local_ip' , lambda x : True
637
- ), pytest .warns (None ) as record :
638
- c = self .connect_client ()
639
- assert len (record ) == 0 , str ([str (w ) for w in record ])
640
- c .close ()
0 commit comments