X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Fintegration%2Ftestlib%2Futil.py;h=f0849b954a5c02173caefc9be566b8a631ab57df;hb=3d787920d51a35e74e442c7265be3b13b69ad8e4;hp=8102bca2762c1d6afc67acee33fc7bbe38aaee6d;hpb=76de8e3924fc36e5a3e906741bf640dceb846800;p=tinc diff --git a/test/integration/testlib/util.py b/test/integration/testlib/util.py index 8102bca2..f0849b95 100755 --- a/test/integration/testlib/util.py +++ b/test/integration/testlib/util.py @@ -7,6 +7,7 @@ import random import string import socket import typing as T +from pathlib import Path from . import check from .log import log @@ -31,6 +32,15 @@ def random_port() -> int: log.debug("could not bind to random port %d", port, exc_info=ex) +def remove_file(path: T.Union[str, Path]) -> bool: + """Try to remove file without failing if it does not exist.""" + try: + os.remove(path) + return True + except FileNotFoundError: + return False + + def random_string(k: int) -> str: """Generate a random alphanumeric string of length k.""" return "".join(random.choices(_ALPHA_NUMERIC, k=k))