Skip to content

Commit 9c95339

Browse files
authored
fix(fill): fix --collect-only after introducing FixtureOutput class (#1612)
* test(fill): add a `CliRunner`-based test for `--collect-only` * fix(fill): evalute output options before returning if `--collect-only` * docs: update changelog
1 parent 722bb63 commit 9c95339

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The output behavior of `fill` has changed ([#1608](https://github.com/ethereum/e
1919

2020
#### `fill`
2121

22-
- 🔀 Refactor: Encapsulate `fill`'s fixture output options (`--output`, `--flat-output`, `--single-fixture-per-file`) into a `FixtureOutput` class ([#1471](https://github.com/ethereum/execution-spec-tests/pull/1471)).
22+
- 🔀 Refactor: Encapsulate `fill`'s fixture output options (`--output`, `--flat-output`, `--single-fixture-per-file`) into a `FixtureOutput` class ([#1471](https://github.com/ethereum/execution-spec-tests/pull/1471),[#1612](https://github.com/ethereum/execution-spec-tests/pull/1612)).
2323
- ✨ Don't warn about a "high Transaction gas_limit" for `zkevm` tests ([#1598](https://github.com/ethereum/execution-spec-tests/pull/1598)).
2424
- 🐞 `fill` no longer writes generated fixtures into an existing, non-empty output directory; it must now be empty or `--clean` must be used to delete it first ([#1608](https://github.com/ethereum/execution-spec-tests/pull/1608)).
2525

src/pytest_plugins/filler/filler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,13 @@ def pytest_configure(config):
222222
# Modify the block gas limit if specified.
223223
if config.getoption("block_gas_limit"):
224224
EnvironmentDefaults.gas_limit = config.getoption("block_gas_limit")
225-
if config.option.collectonly:
226-
return
227225

228226
# Initialize fixture output configuration
229227
config.fixture_output = FixtureOutput.from_config(config)
230228

229+
if config.option.collectonly:
230+
return
231+
231232
try:
232233
# Check whether the directory exists and is not empty; if --clean is set, it will delete it
233234
config.fixture_output.create_directories(is_master=not hasattr(config, "workerinput"))
@@ -865,7 +866,6 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
865866
return
866867

867868
fixture_output = session.config.fixture_output # type: ignore[attr-defined]
868-
# When using --collect-only it should not matter whether fixtures folder exists or not
869869
if fixture_output.is_stdout or session.config.option.collectonly:
870870
return
871871

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Test the fill command's --collect-only pytest option."""
2+
3+
import textwrap
4+
5+
from click.testing import CliRunner
6+
7+
from cli.pytest_commands.fill import fill
8+
9+
test_module_dummy = textwrap.dedent(
10+
"""\
11+
import pytest
12+
13+
from ethereum_test_tools import Environment
14+
15+
@pytest.mark.valid_at("Istanbul")
16+
def test_dummy_collect_only_test(state_test):
17+
state_test(env=Environment(), pre={}, post={}, tx=None)
18+
"""
19+
)
20+
21+
22+
def test_collect_only_output(testdir):
23+
"""Test that --collect-only option produces expected output."""
24+
tests_dir = testdir.mkdir("tests")
25+
istanbul_tests_dir = tests_dir.mkdir("istanbul")
26+
dummy_dir = istanbul_tests_dir.mkdir("dummy_test_module")
27+
test_module = dummy_dir.join("test_dummy_collect.py")
28+
test_module.write(test_module_dummy)
29+
30+
testdir.copy_example(name="pytest.ini")
31+
32+
runner = CliRunner()
33+
result = runner.invoke(
34+
fill,
35+
[
36+
"--fork",
37+
"Istanbul",
38+
"tests/istanbul/dummy_test_module/",
39+
"--collect-only",
40+
"-q",
41+
],
42+
)
43+
44+
assert result.exit_code == 0, f"Fill command failed:\n{result.output}"
45+
46+
assert (
47+
"tests/istanbul/dummy_test_module/test_dummy_collect.py::test_dummy_collect_only_test[fork_Istanbul-state_test]"
48+
in result.output
49+
)
50+
assert (
51+
"tests/istanbul/dummy_test_module/test_dummy_collect.py::test_dummy_collect_only_test[fork_Istanbul-blockchain_test_from_state_test]"
52+
in result.output
53+
)
54+
# fill generates 3 test variants: state_test, blockchain_test, and blockchain_test_engine
55+
assert "3 tests collected" in result.output

0 commit comments

Comments
 (0)