@@ -3506,23 +3506,22 @@ class ProgramPriorityTests(unittest.TestCase):
3506
3506
"""Tests for os.getpriority() and os.setpriority()."""
3507
3507
3508
3508
def test_set_get_priority (self ):
3509
-
3510
3509
base = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3511
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base + 1 )
3512
- try :
3513
- new_prio = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3514
- # nice value cap is 19 for linux and 20 for FreeBSD
3515
- if base >= 19 and new_prio <= base :
3516
- raise unittest . SkipTest ( "unable to reliably test setpriority "
3517
- "at current nice level of %s" % base )
3518
- else :
3519
- self . assertEqual ( new_prio , base + 1 )
3520
- finally :
3521
- try :
3522
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base )
3523
- except OSError as err :
3524
- if err . errno != errno . EACCES :
3525
- raise
3510
+ code = f"""if 1:
3511
+ import os
3512
+ os.setpriority (os.PRIO_PROCESS, os.getpid(), { base } + 1 )
3513
+ print(os.getpriority(os.PRIO_PROCESS, os.getpid()))
3514
+ """
3515
+
3516
+ # Subprocess inherits the current process' priority.
3517
+ _ , out , _ = assert_python_ok ( "-c" , code )
3518
+ new_prio = int ( out )
3519
+ # nice value cap is 19 for linux and 20 for FreeBSD
3520
+ if base >= 19 and new_prio <= base :
3521
+ raise unittest . SkipTest ( "unable to reliably test setpriority "
3522
+ "at current nice level of %s" % base )
3523
+ else :
3524
+ self . assertEqual ( new_prio , base + 1 )
3526
3525
3527
3526
3528
3527
@unittest .skipUnless (hasattr (os , 'sendfile' ), "test needs os.sendfile()" )
0 commit comments