@@ -3485,23 +3485,22 @@ class ProgramPriorityTests(unittest.TestCase):
3485
3485
"""Tests for os.getpriority() and os.setpriority()."""
3486
3486
3487
3487
def test_set_get_priority (self ):
3488
-
3489
3488
base = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3490
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base + 1 )
3491
- try :
3492
- new_prio = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3493
- # nice value cap is 19 for linux and 20 for FreeBSD
3494
- if base >= 19 and new_prio <= base :
3495
- raise unittest . SkipTest ( "unable to reliably test setpriority "
3496
- "at current nice level of %s" % base )
3497
- else :
3498
- self . assertEqual ( new_prio , base + 1 )
3499
- finally :
3500
- try :
3501
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base )
3502
- except OSError as err :
3503
- if err . errno != errno . EACCES :
3504
- raise
3489
+ code = f"""if 1:
3490
+ import os
3491
+ os.setpriority (os.PRIO_PROCESS, os.getpid(), { base } + 1 )
3492
+ print(os.getpriority(os.PRIO_PROCESS, os.getpid()))
3493
+ """
3494
+
3495
+ # Subprocess inherits the current process' priority.
3496
+ _ , out , _ = assert_python_ok ( "-c" , code )
3497
+ new_prio = int ( out )
3498
+ # nice value cap is 19 for linux and 20 for FreeBSD
3499
+ if base >= 19 and new_prio <= base :
3500
+ raise unittest . SkipTest ( "unable to reliably test setpriority "
3501
+ "at current nice level of %s" % base )
3502
+ else :
3503
+ self . assertEqual ( new_prio , base + 1 )
3505
3504
3506
3505
3507
3506
@unittest .skipUnless (hasattr (os , 'sendfile' ), "test needs os.sendfile()" )
0 commit comments