1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/env python
import pytest
if pytest.PLATFORM == "win32":
pytest.skip("Unsupported Platform")
import sys
from os import kill
from time import sleep
from errno import ESRCH
from signal import SIGTERM
from subprocess import Popen
from . import app
def is_running(pid):
try:
kill(pid, 0)
except OSError as error:
if error.errno == ESRCH:
return False
return True
def wait(pid, timeout=3):
count = timeout
while is_running(pid) and count:
sleep(1)
def test(tmpdir):
tmpdir.ensure("app.pid")
pid_path = tmpdir.join("app.pid")
args = [sys.executable, app.__file__, str(pid_path)]
Popen(args, env={'PYTHONPATH': ':'.join(sys.path)}).wait()
sleep(1)
assert pid_path.check(exists=True, file=True)
pid = None
with pid_path.open() as f:
pid = int(f.read().strip())
assert isinstance(pid, int)
assert pid > 0
kill(pid, SIGTERM)
wait(pid)
|