Skip to content

Commit

Permalink
Handle coverage module backward incompatibility
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grouigrokon committed May 29, 2024
1 parent e6ec589 commit 4b2caa6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/e3/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4b2caa6

Please sign in to comment.