From 2ddeb71764507d31d49ddd6895bfee6bc3304b75 Mon Sep 17 00:00:00 2001 From: Mattias Lindvall Date: Tue, 5 Feb 2019 17:56:43 +0100 Subject: [PATCH 1/3] remove irrelevant exception from test case this is not actually used, must be some old artefact from refactoring --- tests/test_pid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pid.py b/tests/test_pid.py index e822094..19184ae 100644 --- a/tests/test_pid.py +++ b/tests/test_pid.py @@ -276,7 +276,7 @@ def test_pid_check_samepid_two_processes(): pidfile_proc1.create() mgetpid.return_value = 2 - with raising(pid.PidFileAlreadyRunningError, pid.PidFileAlreadyLockedError): + with raising(pid.PidFileAlreadyRunningError): pidfile_proc2.create() finally: pidfile_proc1.close() From 80957ec321868fc87f7cbe1ba092ec898d7218d0 Mon Sep 17 00:00:00 2001 From: Mattias Lindvall Date: Tue, 5 Feb 2019 17:57:49 +0100 Subject: [PATCH 2/3] improve tets case name --- tests/test_pid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pid.py b/tests/test_pid.py index 19184ae..bc54536 100644 --- a/tests/test_pid.py +++ b/tests/test_pid.py @@ -266,7 +266,7 @@ def test_pid_check_samepid(): pidfile.close() -def test_pid_check_samepid_two_processes(): +def test_pid_raises_already_running_when_samepid_and_two_different_pids(): pidfile_proc1 = pid.PidFile() pidfile_proc2 = pid.PidFile(allow_samepid=True) From edd07d29656cbda5742b7b03be4bf8b9020c9e89 Mon Sep 17 00:00:00 2001 From: Mattias Lindvall Date: Tue, 5 Feb 2019 17:59:25 +0100 Subject: [PATCH 3/3] add mocking of os.kill to test case so it doesnt query the real process table --- tests/test_pid.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/test_pid.py b/tests/test_pid.py index bc54536..e3ba747 100644 --- a/tests/test_pid.py +++ b/tests/test_pid.py @@ -266,18 +266,22 @@ def test_pid_check_samepid(): pidfile.close() -def test_pid_raises_already_running_when_samepid_and_two_different_pids(): +@patch("os.getpid") +@patch("os.kill") +def test_pid_raises_already_running_when_samepid_and_two_different_pids( + mock_getpid, mock_kill, +): pidfile_proc1 = pid.PidFile() pidfile_proc2 = pid.PidFile(allow_samepid=True) try: - with patch('pid.os.getpid') as mgetpid: - mgetpid.return_value = 1 - pidfile_proc1.create() + mock_getpid.return_value = 1 + pidfile_proc2.create() + + mock_getpid.return_value = 2 + with raising(pid.PidFileAlreadyRunningError): + pidfile_proc2.create() - mgetpid.return_value = 2 - with raising(pid.PidFileAlreadyRunningError): - pidfile_proc2.create() finally: pidfile_proc1.close() pidfile_proc2.close()