Merge branch 'juerg/artifactshare' into 'master'

tests/testutils/artifactshare.py: Add SIGTERM handler to subprocess

See merge request BuildStream/buildstream!1606
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index f883b3d..87b0808 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 @@
     #
     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: