-
Notifications
You must be signed in to change notification settings - Fork 187
fix(fill): skip fixture index generation if output dir is not clean #1348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -250,6 +250,26 @@ def pytest_configure(config): | |||||||||||||||||||||||||||||||||||||||||||||||||||
| config.stash[metadata_key]["Command-line args"] = f"<code>{command_line_args}</code>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pytest_sessionstart(session: pytest.Session): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Check if the output directory was clean at session start.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| output: Path = session.config.getoption("output") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_dir = strip_output_tarball_suffix(output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if is_output_stdout(output) or session.config.option.collectonly: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| session.config._output_dir_was_clean = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if output_dir.exists() and any(output_dir.iterdir()): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matt, the following was detected by debugging the failing unit test (https://github.com/ethereum/execution-spec-tests/actions/runs/14051860205/job/39344901008#step:5:48). Unfortunately, this doesn't quite work due to some funky, non-obvious interaction with the pytest-html plugin. We hijack the pytest-html command-line args in execution-spec-tests/src/pytest_plugins/filler/filler.py Lines 216 to 221 in b4e09b1
It seems to me that this plugin ensures that the target directory (which is I think the only way to fix this is to unfortunately move this check up to I confirmed this by running the execution-spec-tests/src/pytest_plugins/consume/tests/test_consume_args.py Lines 55 to 73 in b4e09b1
from the problematic unit test: -> dir exists Adding the -> the index file is generated as expected. This was a tricky one! |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| session.config._output_dir_was_clean = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we discussed a warning here, but after seeing the output, which is quite noisy for little information: I think the better approach would be to append a line to the pytest session header using this hook:
Similar to the warning in the header generated from the forks plugin highlighted here: |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"[filler] Output directory '{output_dir}' is not empty at session start. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Index generation will be skipped to avoid parsing stale fixtures.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stacklevel=2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| session.config._output_dir_was_clean = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| @pytest.hookimpl(trylast=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pytest_report_header(config: pytest.Config): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Add lines to pytest's console output header.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -817,11 +837,19 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int): | |||||||||||||||||||||||||||||||||||||||||||||||||||
| for file in output_dir.rglob("*.lock"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| file.unlink() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Generate index file for all produced fixtures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Skip index generation if output dir was not clean at session start to avoid stale fixture | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if session.config.getoption("generate_index"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_fixtures_index( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_dir, quiet_mode=True, force_flag=False, disable_infer_format=False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| was_clean = getattr(session.config, "_output_dir_was_clean", True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if was_clean is True: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| generate_fixtures_index( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_dir, quiet_mode=True, force_flag=False, disable_infer_format=False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif was_clean is False: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"[filler] Skipping index file generation because the output directory " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"'{output_dir}' was not clean at session start.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stacklevel=2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create tarball of the output directory if the output is a tarball. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_output_tarball = output.suffix == ".gz" and output.with_suffix("").suffix == ".tar" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.