bpo-22367: Update test_fcntl.py for spawn process mode (GH-17154) (GH-17252)
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
https://github.com/python/cpython/commit/c3cd0de9ec7ab54186cebef5b2edfd098f7... commit: c3cd0de9ec7ab54186cebef5b2edfd098f7ae387 branch: 3.8 author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> committer: Victor Stinner <vstinner@python.org> date: 2019-11-22T15:15:36+01:00 summary: bpo-22367: Update test_fcntl.py for spawn process mode (GH-17154) (GH-17252) (cherry picked from commit 9960230f76eb555d6dfbe8a324efed35610c85f9) Co-authored-by: Dong-hee Na <donghee.na92@gmail.com> files: M Lib/test/test_fcntl.py diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 88d989d5e358d..c394f6945a8d2 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -51,6 +51,21 @@ def __init__(self, fn): def fileno(self): return self.fn +def try_lockf_on_other_process_fail(fname, cmd): + f = open(fname, 'wb+') + try: + fcntl.lockf(f, cmd) + except BlockingIOError: + pass + finally: + f.close() + +def try_lockf_on_other_process(fname, cmd): + f = open(fname, 'wb+') + fcntl.lockf(f, cmd) + fcntl.lockf(f, fcntl.LOCK_UN) + f.close() + class TestFcntl(unittest.TestCase): def setUp(self): @@ -138,28 +153,23 @@ def test_flock(self): self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH) self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH) + @unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError") def test_lockf_exclusive(self): self.f = open(TESTFN, 'wb+') cmd = fcntl.LOCK_EX | fcntl.LOCK_NB - def try_lockf_on_other_process(): - self.assertRaises(BlockingIOError, fcntl.lockf, self.f, cmd) - fcntl.lockf(self.f, cmd) - p = Process(target=try_lockf_on_other_process) + p = Process(target=try_lockf_on_other_process_fail, args=(TESTFN, cmd)) p.start() p.join() fcntl.lockf(self.f, fcntl.LOCK_UN) self.assertEqual(p.exitcode, 0) + @unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError") def test_lockf_share(self): self.f = open(TESTFN, 'wb+') cmd = fcntl.LOCK_SH | fcntl.LOCK_NB - def try_lockf_on_other_process(): - fcntl.lockf(self.f, cmd) - fcntl.lockf(self.f, fcntl.LOCK_UN) - fcntl.lockf(self.f, cmd) - p = Process(target=try_lockf_on_other_process) + p = Process(target=try_lockf_on_other_process, args=(TESTFN, cmd)) p.start() p.join() fcntl.lockf(self.f, fcntl.LOCK_UN)
participants (1)
-
Victor Stinner