diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 5cab15f15..54d9230ce 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -1,40 +1,67 @@ +import signal +import sys +from typing import List import pytest import subprocess import pathlib import os import time +def spawn_process(command: List[str]) -> subprocess.Popen: + if sys.platform.startswith("win32"): + command[0] = "python" + process = subprocess.Popen(command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) + return process + process = subprocess.Popen(command, preexec_fn=os.setsid) + return process + -@pytest.fixture + +def kill_process(process: subprocess.Popen) -> None: + if sys.platform.startswith("win32"): + process.send_signal(signal.CTRL_BREAK_EVENT) + process.kill() + return + os.killpg(os.getpgid(process.pid), signal.SIGKILL) + + + + +@pytest.fixture(scope="session") def session(): os.environ["ROBYN_URL"] = "127.0.0.1" current_file_path = pathlib.Path(__file__).parent.resolve() base_routes = os.path.join(current_file_path, "./base_routes.py") - process = subprocess.Popen(["python3", base_routes]) + command = ["python3", base_routes] + process = spawn_process(command) time.sleep(5) yield - process.terminate() + kill_process(process) + + -@pytest.fixture +@pytest.fixture(scope="session") def default_session(): current_file_path = pathlib.Path(__file__).parent.resolve() base_routes = os.path.join(current_file_path, "./base_routes.py") - process = subprocess.Popen(["python3", base_routes]) + command = ["python3", base_routes] + process = spawn_process(command) time.sleep(5) yield - process.terminate() + kill_process(process) -@pytest.fixture +@pytest.fixture(scope="session") def global_session(): os.environ["ROBYN_URL"] = "0.0.0.0" current_file_path = pathlib.Path(__file__).parent.resolve() base_routes = os.path.join(current_file_path, "./base_routes.py") - process = subprocess.Popen(["python3", base_routes]) + command = ["python3", base_routes] + process = spawn_process(command) time.sleep(1) yield - process.terminate() + kill_process(process) @pytest.fixture(scope="session") @@ -43,8 +70,8 @@ def dev_session(): os.environ["ROBYN_PORT"] = "5001" current_file_path = pathlib.Path(__file__).parent.resolve() base_routes = os.path.join(current_file_path, "./base_routes.py") - process = subprocess.Popen(["python3", base_routes, "--dev"]) + command = ["python3", base_routes, "--dev"] + process = spawn_process(command) time.sleep(5) yield - process.terminate() - + kill_process(process) \ No newline at end of file