@@ -143,16 +143,20 @@ def test_clock_getres(self):
143143
144144 @unittest .skipUnless (hasattr (time , 'clock_settime' ),
145145 'need time.clock_settime()' )
146+ @support .requires_resource ('settime' )
146147 def test_clock_settime (self ):
147148 t = time .clock_gettime (time .CLOCK_REALTIME )
148149 try :
149150 time .clock_settime (time .CLOCK_REALTIME , t )
150151 except PermissionError :
151152 pass
152153
153- if hasattr (time , 'CLOCK_MONOTONIC' ):
154- self .assertRaises (OSError ,
155- time .clock_settime , time .CLOCK_MONOTONIC , 0 )
154+ @unittest .skipUnless (hasattr (time , 'clock_settime' ) and
155+ hasattr (time , 'CLOCK_MONOTONIC' ),
156+ 'need clock_settime() and CLOCK_MONOTONIC' )
157+ def test_clock_settime_monotonic (self ):
158+ with self .assertRaises (OSError ):
159+ time .clock_settime (time .CLOCK_MONOTONIC , 0 )
156160
157161 def test_large_timestamp_year (self ):
158162 # 2147483648-06-29 00:00:00 UTC, away from local year boundaries.
@@ -703,6 +707,7 @@ def test_thread_time(self):
703707
704708 @unittest .skipUnless (hasattr (time , 'clock_settime' ),
705709 'need time.clock_settime' )
710+ @support .requires_resource ('settime' )
706711 def test_monotonic_settime (self ):
707712 t1 = time .monotonic ()
708713 realtime = time .clock_gettime (time .CLOCK_REALTIME )
@@ -711,8 +716,10 @@ def test_monotonic_settime(self):
711716 time .clock_settime (time .CLOCK_REALTIME , realtime - 3600 )
712717 except PermissionError as err :
713718 self .skipTest (err )
714- t2 = time .monotonic ()
715- time .clock_settime (time .CLOCK_REALTIME , realtime )
719+ try :
720+ t2 = time .monotonic ()
721+ finally :
722+ time .clock_settime (time .CLOCK_REALTIME , realtime )
716723 # monotonic must not be affected by system clock updates
717724 self .assertGreaterEqual (t2 , t1 )
718725
0 commit comments