From 6ad1761d2f1798db21497265ae2efaae8bdcb844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Mon, 16 Sep 2019 21:01:16 +0200 Subject: tests/testutils/artifactshare.py: Add SIGTERM handler to subprocess pytest-cov 2.7 calls os._exit() in its SIGTERM handler, skipping cleanup, unless another SIGTERM handler was already registered. Add our own SIGTERM handler to the subprocess to ensure proper cleanup such as terminating buildbox-casd. --- tests/testutils/artifactshare.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/testutils') diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py index f883b3d59..87b0808fe 100644 --- a/tests/testutils/artifactshare.py +++ b/tests/testutils/artifactshare.py @@ -1,6 +1,7 @@ import os import shutil import signal +import sys from collections import namedtuple from contextlib import contextmanager @@ -63,6 +64,11 @@ class ArtifactShare(): # def run(self, q): + # Handle SIGTERM by calling sys.exit(0), which will raise a SystemExit exception, + # properly executing cleanup code in `finally` clauses and context managers. + # This is required to terminate buildbox-casd on SIGTERM. + signal.signal(signal.SIGTERM, lambda signalnum, frame: sys.exit(0)) + try: import pytest_cov except ImportError: -- cgit v1.2.1