Skip to content

Commit

Permalink
Merge branch 'master' of github.com:trbs/pid
Browse files Browse the repository at this point in the history
* 'master' of github.com:trbs/pid:
  add mocking of os.kill to test case
  improve tets case name
  remove irrelevant exception from test case
  • Loading branch information
trbs committed Feb 7, 2019
2 parents 68bf722 + 0d97ba3 commit efe1367
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/test_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,22 @@ def test_pid_check_samepid():
pidfile.close()


def test_pid_check_samepid_two_processes():
@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, pid.PidFileAlreadyLockedError):
pidfile_proc2.create()
finally:
pidfile_proc1.close()
pidfile_proc2.close()
Expand Down

0 comments on commit efe1367

Please sign in to comment.