From 4b2caa6c62208e339fb70901c1736df793f49625 Mon Sep 17 00:00:00 2001 From: Frederic Leger Date: Wed, 29 May 2024 12:22:47 +0200 Subject: [PATCH] Handle coverage module backward incompatibility The `CoverageData.update()` method is not compatible between 7.5.2 and any later version. Catch the exception and call the method with old parameters if needed. --- src/e3/pytest.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/e3/pytest.py b/src/e3/pytest.py index d878a38e..6c1a8244 100644 --- a/src/e3/pytest.py +++ b/src/e3/pytest.py @@ -209,7 +209,20 @@ def fix_coverage_paths(origin_dir: str, new_dir: str, cov_db: str) -> None: old_coverage_data = CoverageData(old_cov_file.name) old_coverage_data.read() new_coverage_data = CoverageData(cov_db) - new_coverage_data.update(old_coverage_data, aliases=paths) + + # Before 7.5.3, the map_path argument (of type Callable[[str], str]) + # was named aliases (of type PathAliases). Try to handle the two + # possible APIs. + try: + # noinspection PyArgumentList + new_coverage_data.update(old_coverage_data, map_path=paths.map) + except TypeError as te: + if "got an unexpected keyword argument 'map_path'" in str(te): + # Try with the old API ... + # noinspection PyArgumentList + new_coverage_data.update(old_coverage_data, aliases=paths) + else: + raise te new_coverage_data.write() finally: os.unlink(old_cov_file.name)