Skip to content

Commit a426eb5

Browse files
committed
Remove file after test completion
1 parent 91bbeb5 commit a426eb5

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Tests/test_image_access.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ def test_embeddable(self) -> None:
276276
except Exception:
277277
pytest.skip("Compiler could not be initialized")
278278

279-
with open("embed_pil.c", "w", encoding="utf-8") as fh:
280-
home = sys.prefix.replace("\\", "\\\\")
281-
fh.write(
282-
f"""
279+
try:
280+
with open("embed_pil.c", "w", encoding="utf-8") as fh:
281+
home = sys.prefix.replace("\\", "\\\\")
282+
fh.write(
283+
f"""
283284
#include "Python.h"
284285
285286
int main(int argc, char* argv[])
@@ -301,17 +302,19 @@ def test_embeddable(self) -> None:
301302
return 0;
302303
}}
303304
"""
304-
)
305+
)
305306

306-
objects = compiler.compile(["embed_pil.c"])
307-
compiler.link_executable(objects, "embed_pil")
307+
objects = compiler.compile(["embed_pil.c"])
308+
compiler.link_executable(objects, "embed_pil")
308309

309-
env = os.environ.copy()
310-
env["PATH"] = sys.prefix + ";" + env["PATH"]
310+
env = os.environ.copy()
311+
env["PATH"] = sys.prefix + ";" + env["PATH"]
311312

312-
# Do not display the Windows Error Reporting dialog
313-
getattr(ctypes, "windll").kernel32.SetErrorMode(0x0002)
313+
# Do not display the Windows Error Reporting dialog
314+
getattr(ctypes, "windll").kernel32.SetErrorMode(0x0002)
314315

315-
process = subprocess.Popen(["embed_pil.exe"], env=env)
316-
process.communicate()
317-
assert process.returncode == 0
316+
process = subprocess.Popen(["embed_pil.exe"], env=env)
317+
process.communicate()
318+
assert process.returncode == 0
319+
finally:
320+
os.remove("embed_pil.c")

0 commit comments

Comments
 (0)