tests/assert-msg-test: fix opening temporary file in GDB

On Win32, the file cannot be opened a second time, it must be closed
first.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-10-14 15:05:25 +04:00
parent 6dcd7fe5e8
commit 52a49eb9c2

View File

@ -146,12 +146,14 @@ class TestAssertMessage(unittest.TestCase):
self.skipTest("GDB is not installed, skipping this test!")
with tempfile.NamedTemporaryFile(
prefix="assert-msg-test-", suffix=".gdb", mode="w"
prefix="assert-msg-test-", suffix=".gdb", mode="w", delete=False
) as tmp:
tmp.write(GDB_SCRIPT)
tmp.flush()
result = self.runGdbAssertMessage("-x", tmp.name, self.__assert_msg_test)
try:
tmp.write(GDB_SCRIPT)
tmp.close()
result = self.runGdbAssertMessage("-x", tmp.name, self.__assert_msg_test)
finally:
os.unlink(tmp.name)
# Some CI environments disable ptrace (as theyre running in a
# container). If so, skip the test as theres nothing we can do.