Skip to content

Commit d30cb94

Browse files
committed
test: fix changelog unit test imports in CI
1 parent 1a88941 commit d30cb94

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

tests/test_update_changelog.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
from scripts.update_changelog import update_changelog_text
1+
import importlib.util
2+
from pathlib import Path
3+
4+
5+
def _update_changelog_text(text: str, ver: str, date: str) -> str:
6+
path = Path(__file__).resolve().parents[1] / "scripts" / "update_changelog.py"
7+
spec = importlib.util.spec_from_file_location("update_changelog", path)
8+
module = importlib.util.module_from_spec(spec)
9+
assert spec.loader is not None
10+
spec.loader.exec_module(module)
11+
return module.update_changelog_text(text, ver, date)
12+
213

314
HEADER = """# Changelog
415
@@ -18,7 +29,7 @@
1829

1930

2031
def test_empty_unreleased_inserts_version_without_duplicate_heading():
21-
result = update_changelog_text(HEADER, "0.1.2", "2026-05-20")
32+
result = _update_changelog_text(HEADER, "0.1.2", "2026-05-20")
2233
assert result.count("## [Unreleased]") == 1
2334
assert "## [0.1.2] - 2026-05-20" in result
2435
assert "The format is based on [Keep a Changelog]" in result.split("## [0.1.2]")[0]
@@ -30,7 +41,7 @@ def test_populated_unreleased_moves_notes_into_new_section():
3041
"## [Unreleased]\n\n",
3142
"## [Unreleased]\n\n### Added\n\n- New widget.\n\n",
3243
)
33-
result = update_changelog_text(text, "0.1.2", "2026-05-20")
44+
result = _update_changelog_text(text, "0.1.2", "2026-05-20")
3445
assert result.count("## [Unreleased]") == 1
3546
assert "- New widget." in result
3647
assert result.index("- New widget.") < result.index("## [0.1.1]")

0 commit comments

Comments
 (0)