Skip to content

Commit 0c3397c

Browse files
authored
fix(github/coverage): Fix coverage script on PRs that do not convert tests (#1661)
* fix(plugins/ported_from): Fix and add `--ported-from-output-file` parameter * fix(github/coverage): Use `--ported-from-output-file` * changelog
1 parent 0157a4b commit 0c3397c

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

.github/workflows/coverage.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ jobs:
120120
new_sources=$(echo "$CHANGED_TEST_FILES" | tr ',' '\n')
121121
echo "Changed or new test files: $new_sources"
122122
123-
# uv run returns an error code if no tests detected in changed files. ignore it by setting || true.
124-
files=$(uv run fill $new_sources --show-ported-from --clean --quiet --links-as-filled | grep .json || true)
123+
uv run fill $new_sources --show-ported-from --clean --quiet --links-as-filled --ported-from-output-file ported_from_files.txt
124+
files=$(cat ported_from_files.txt)
125125
echo "Extracted converted tests: $files"
126-
127126
if [[ -z "$files" ]]; then
128127
echo "No ported fillers found, check updates instead:"
129128
echo "converted_skip=true" >> $GITHUB_ENV

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Users can select any of the artifacts depending on their testing needs for their
4545
- ✨ Added a new `eest` sub-command, `eest info`, to easily print a cloned EEST repository's version and the versions of relevant tools, e.g., `python`, `uv` ([#1621](https://github.com/ethereum/execution-spec-tests/pull/1621)).
4646
- ✨ Add `CONTRIBUTING.md` for execution-spec-tests and improve coding standards documentation ([#1604](https://github.com/ethereum/execution-spec-tests/pull/1604)).
4747
- 🔀 Updated from pytest 7 to [pytest 8](https://docs.pytest.org/en/stable/changelog.html#features-and-improvements), benefits include improved type hinting and hook typing, stricter mark handling, and clearer error messages for plugin and metadata development [#1433](https://github.com/ethereum/execution-spec-tests/pull/1433).
48+
- 🐞 Fix bug in ported-from plugin and coverage script that made PRs fail with modified tests that contained no ported tests ([#1661](https://github.com/ethereum/execution-spec-tests/pull/1661)).
4849

4950
### 🧪 Test Cases
5051

src/pytest_plugins/filler/ported_tests.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"""
3131

3232
import re
33-
from typing import Set
33+
from typing import List, Set
3434
from urllib.parse import urlparse
3535

3636
import pytest
@@ -72,6 +72,13 @@ def pytest_addoption(parser: pytest.Parser):
7272
"Use '--show-ported-from=prs' to show PR URLs."
7373
),
7474
)
75+
ported_from_group.addoption(
76+
"--ported-from-output-file",
77+
action="store",
78+
dest="ported_from_output_file",
79+
default=None,
80+
help="Output file for ported_from information.",
81+
)
7582
ported_from_group.addoption(
7683
"--links-as-filled",
7784
action="store_true",
@@ -99,9 +106,15 @@ def __init__(self, config) -> None:
99106
self.config = config
100107
self.show_mode = config.getoption("show_ported_from")
101108
self.links_as_filled = config.getoption("links_as_filled")
109+
self.ported_from_output_file = config.getoption("ported_from_output_file")
102110

103111
@pytest.hookimpl(hookwrapper=True, trylast=True)
104-
def pytest_collection_modifyitems(self, session, config, items):
112+
def pytest_collection_modifyitems(
113+
self,
114+
session: pytest.Session,
115+
config: pytest.Config,
116+
items: List[pytest.Item],
117+
):
105118
"""Extract ported_from information from collected test items."""
106119
yield
107120

@@ -133,25 +146,27 @@ def pytest_collection_modifyitems(self, session, config, items):
133146

134147
# Output results based on mode
135148
if self.show_mode == "prs":
136-
output = sorted(prs)
149+
outputs = sorted(prs)
137150
else: # default to "paths"
138-
output = sorted(paths)
139-
151+
outputs = sorted(paths)
152+
output_lines: List[str] = []
140153
if self.links_as_filled:
141-
all_files: list = []
142-
for item in output:
143-
converted_link = convert_to_filled(item)
144-
if converted_link is not None:
145-
all_files.append(converted_link)
146-
print(" ".join(all_files))
154+
for output in outputs:
155+
converted_link_output = convert_to_filled(output)
156+
if converted_link_output is not None:
157+
output_lines.append(converted_link_output)
158+
else:
159+
output_lines.extend(outputs)
160+
if self.ported_from_output_file:
161+
with open(self.ported_from_output_file, "w") as f:
162+
f.write("\n".join(output_lines))
147163
else:
148-
for item in output:
149-
print(item)
164+
for line in output_lines:
165+
print(line)
150166

151167
@pytest.hookimpl(tryfirst=True)
152168
def pytest_runtestloop(self, session):
153169
"""Skip test execution, only show ported_from information."""
154-
session.testscollected = 0
155170
return True
156171

157172
def pytest_terminal_summary(self, terminalreporter, exitstatus, config):

0 commit comments

Comments
 (0)