From 8ce4f91d7b539f322371de0bf7802a14f62d151c Mon Sep 17 00:00:00 2001 From: Michael Bourke Date: Fri, 10 Dec 2021 15:28:11 +1100 Subject: Fix 3.7 and Windows problems Change-Id: Iec9544a055a1a2e3e2a87b8dce8360ffa64a67c3 --- test/util/helpers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/util/helpers.py b/test/util/helpers.py index 0ca4c2d..86402c8 100644 --- a/test/util/helpers.py +++ b/test/util/helpers.py @@ -19,9 +19,19 @@ def result_lines(result): ] +def _unlink_path(path, missing_ok=False): + # Replicate 3.8+ functionality in 3.7 + cm = contextlib.nullcontext() + if missing_ok: + cm = contextlib.suppress(FileNotFoundError) + + with cm: + path.unlink() + + def replace_file_with_dir(pathspec): path = pathlib.Path(pathspec) - path.unlink(missing_ok=True) + _unlink_path(path, missing_ok=True) path.mkdir(exist_ok=True) return path -- cgit v1.2.1