From 70c16361e836f325419a36adc6c5726988ac2951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Mon, 22 Dec 2025 11:05:54 +0000 Subject: [PATCH 1/2] Fix compatibility with testtools 2.8.2 LP: #2136951 --- python/subunit/tests/test_test_protocol2.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/subunit/tests/test_test_protocol2.py b/python/subunit/tests/test_test_protocol2.py index 6d1e03b..2252653 100644 --- a/python/subunit/tests/test_test_protocol2.py +++ b/python/subunit/tests/test_test_protocol2.py @@ -30,7 +30,12 @@ from testtools import TestCase from testtools.matchers import Contains, HasLength from testtools.testresult.doubles import StreamResult -from testtools.tests.test_testresult import TestStreamResultContract + +try: + from testtools.tests.test_testresult import TestStreamResultContract +except ImportError: + # testtools >= 2.8 no longer includes the tests submodule + TestStreamResultContract = None import subunit import iso8601 @@ -54,11 +59,12 @@ ] -class TestStreamResultToBytesContract(TestCase, TestStreamResultContract): - """Check that StreamResult behaves as testtools expects.""" +if TestStreamResultContract is not None: + class TestStreamResultToBytesContract(TestCase, TestStreamResultContract): + """Check that StreamResult behaves as testtools expects.""" - def _make_result(self): - return subunit.StreamResultToBytes(BytesIO()) + def _make_result(self): + return subunit.StreamResultToBytes(BytesIO()) class TestStreamResultToBytes(TestCase): From f1ba01ab7af0dfb7101bb35a992be2e10e9051ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Mon, 22 Dec 2025 11:46:31 +0000 Subject: [PATCH 2/2] Fix ExecTestCase to work without executable permissions Fixes: https://bugs.launchpad.net/subunit/+bug/1323410 --- python/subunit/__init__.py | 7 ++++++- python/subunit/tests/test_test_protocol2.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 9c4fa5d..2d5c118 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -913,7 +913,12 @@ def debug(self): def _run(self, result): protocol = TestProtocolServer(result) - process = subprocess.Popen(self.script, shell=True, stdout=subprocess.PIPE) + # Explicitly invoke Python to run the script instead of relying on + # execute permissions, which may not be preserved during installation + import shlex + + script_parts = shlex.split(self.script) + process = subprocess.Popen([sys.executable] + script_parts, stdout=subprocess.PIPE) make_stream_binary(process.stdout) output = process.communicate()[0] protocol.readFrom(BytesIO(output)) diff --git a/python/subunit/tests/test_test_protocol2.py b/python/subunit/tests/test_test_protocol2.py index 2252653..2874e43 100644 --- a/python/subunit/tests/test_test_protocol2.py +++ b/python/subunit/tests/test_test_protocol2.py @@ -60,6 +60,7 @@ if TestStreamResultContract is not None: + class TestStreamResultToBytesContract(TestCase, TestStreamResultContract): """Check that StreamResult behaves as testtools expects."""