@@ -3320,23 +3320,22 @@ class ProgramPriorityTests(unittest.TestCase):
3320
3320
"""Tests for os.getpriority() and os.setpriority()."""
3321
3321
3322
3322
def test_set_get_priority (self ):
3323
-
3324
3323
base = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3325
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base + 1 )
3326
- try :
3327
- new_prio = os .getpriority (os .PRIO_PROCESS , os .getpid ())
3328
- # nice value cap is 19 for linux and 20 for FreeBSD
3329
- if base >= 19 and new_prio <= base :
3330
- raise unittest . SkipTest ( "unable to reliably test setpriority "
3331
- "at current nice level of %s" % base )
3332
- else :
3333
- self . assertEqual ( new_prio , base + 1 )
3334
- finally :
3335
- try :
3336
- os . setpriority ( os . PRIO_PROCESS , os . getpid (), base )
3337
- except OSError as err :
3338
- if err . errno != errno . EACCES :
3339
- raise
3324
+ code = f"""if 1:
3325
+ import os
3326
+ os.setpriority (os.PRIO_PROCESS, os.getpid(), { base } + 1 )
3327
+ print(os.getpriority(os.PRIO_PROCESS, os.getpid()))
3328
+ """
3329
+
3330
+ # Subprocess inherits the current process' priority.
3331
+ _ , out , _ = assert_python_ok ( "-c" , code )
3332
+ new_prio = int ( out )
3333
+ # nice value cap is 19 for linux and 20 for FreeBSD
3334
+ if base >= 19 and new_prio <= base :
3335
+ raise unittest . SkipTest ( "unable to reliably test setpriority "
3336
+ "at current nice level of %s" % base )
3337
+ else :
3338
+ self . assertEqual ( new_prio , base + 1 )
3340
3339
3341
3340
3342
3341
@unittest .skipUnless (hasattr (os , 'sendfile' ), "test needs os.sendfile()" )
0 commit comments