Skip to content

Commit

Permalink
Merge pull request #21 from thnee/fix_test_issues
Browse files Browse the repository at this point in the history
Fix some issues in a test case
  • Loading branch information
trbs authored Feb 5, 2019
2 parents d1d70ec + edd07d2 commit 0d97ba3
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 0d97ba3

Please sign in to comment.