From f7bb373ed3825311c007e414bcb52965577a34ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Or=C5=82owski?= Date: Mon, 22 Jun 2026 14:09:38 +0200 Subject: [PATCH] shutil.rmtree parameters fix for python 3.10 --- tests/functional/utils/test_framework.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/functional/utils/test_framework.py b/tests/functional/utils/test_framework.py index f451909b12..f991757b22 100644 --- a/tests/functional/utils/test_framework.py +++ b/tests/functional/utils/test_framework.py @@ -18,6 +18,7 @@ import re import shutil import stat +import sys import traceback import pytest @@ -275,8 +276,14 @@ def _make_path_writable_and_retry(func, path, _exc_info): def remove_dir_tree(dir_path, ignore_errors=False): """Remove a directory tree, retrying failed paths after making them writable.""" + # shutil.rmtree accepts the `onexc` callback only on Python 3.12+; + # older interpreters expect `onerror`. Both invoke the same (func, path, *) callback. + if sys.version_info >= (3, 12): + rmtree_kwargs = {"onexc": _make_path_writable_and_retry} + else: + rmtree_kwargs = {"onerror": _make_path_writable_and_retry} try: - shutil.rmtree(dir_path, onexc=_make_path_writable_and_retry) + shutil.rmtree(dir_path, **rmtree_kwargs) except OSError: if not ignore_errors: raise