From 3bc8de98e68cafe81385336e908efff58e85ad91 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 15 Dec 2018 16:23:06 +0000 Subject: [PATCH] Kill all dummy processes after launch Just in case --- tests/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 0d82441..0f39144 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,6 +2,7 @@ import functools import os import shutil import subprocess +from unittest import TestCase from aiohttp.test_utils import AioHTTPTestCase, unused_port from aiounittest import AsyncTestCase @@ -9,11 +10,15 @@ from click.testing import CliRunner from catfish.__main__ import cli from catfish.router import get_server -from catfish.utils.processes import terminate_subprocesses +from catfish.utils.processes import ( + get_root_process, + terminate_processes, + terminate_subprocesses, +) from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir -class BaseTestCase(AsyncTestCase): +class BaseTestCase(TestCase): DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py") def setUp(self): @@ -22,8 +27,16 @@ class BaseTestCase(AsyncTestCase): self.cli = cli self.run_cli = functools.partial(self.cli_runner.invoke, self.cli) + def terminate_dummy_processes(self): + dummy_processes = [] + for process in get_root_process().children(recursive=True): + if self.DUMMY_EXE in " ".join(process.cmdline()): + dummy_processes.append(process) + terminate_processes(dummy_processes) + def tearDown(self): terminate_subprocesses() + self.terminate_dummy_processes() delete_base_socket_dir()