-
Notifications
You must be signed in to change notification settings - Fork 14
Fix spurious 'no result set' warnings and dropped execution tags under pytest-forked #124
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
Merged
gchan
merged 3 commits into
buildkite:main
from
dahtey-bk:fix-forked-child-finalization
Jul 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """Integration tests for fork-per-test runners (pytest-forked). | ||
|
|
||
| pytest-forked runs each test protocol in a forked child process with | ||
| log=False, then replays the serialized reports in the parent. The child | ||
| inherits a copy of the plugin state that is discarded on exit; only the | ||
| parent's payload is uploaded. These tests verify that the collector | ||
| produces correct results (with execution tags, and without spurious | ||
| 'no result set at finalization' warnings) in that mode. | ||
| """ | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| pytest.importorskip("pytest_forked") | ||
|
|
||
| # pytest-forked needs py.process from the real py package. In layered | ||
| # environments (e.g. `uv run --with pytest`), pytest's vendored py.py shim | ||
| # (py.error/py.path only) can shadow the real package, breaking pytest-forked | ||
| # itself with an INTERNALERROR — nothing our collector can be tested against. | ||
| _py = pytest.importorskip("py") | ||
| if not hasattr(_py, "process"): | ||
| pytest.skip( | ||
| "'py' resolves to pytest's vendored shim without py.process; " | ||
| "pytest-forked cannot run in this environment", | ||
| allow_module_level=True, | ||
| ) | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not hasattr(os, "fork"), reason="pytest-forked requires os.fork" | ||
| ) | ||
|
|
||
|
|
||
| def test_forked_run_collects_results_and_tags_without_warnings(tmp_path): | ||
| """Run pytest with --forked and verify results, tags, and clean logs.""" | ||
| test_file = Path(__file__).parent / "data" / "test_sample_execution_tag.py" | ||
| json_output_file = tmp_path / "test_results.json" | ||
|
|
||
| cmd = [ | ||
| sys.executable, "-m", "pytest", | ||
| "--forked", | ||
| str(test_file), | ||
| f"--json={json_output_file}", | ||
| ] | ||
|
|
||
| result = subprocess.run(cmd, capture_output=True, text=True) | ||
| if result.returncode != 0: | ||
| print(result.stdout) | ||
| print(result.stderr) | ||
| pytest.fail("pytest run failed, see output above") | ||
|
|
||
| output = result.stdout + result.stderr | ||
| assert "has no result set at finalization" not in output | ||
|
|
||
| with open(json_output_file, "r") as f: | ||
| test_results = json.load(f) | ||
|
|
||
| tests_by_name = {test["name"]: test for test in test_results} | ||
|
|
||
| assert len(tests_by_name) == 3 | ||
| for test in test_results: | ||
| assert test["result"] == "passed" | ||
|
|
||
| assert tests_by_name["test_with_multiple_tags"]["tags"] == { | ||
| "language.version": "3.12", | ||
| "team": "backend", | ||
| } | ||
| assert tests_by_name["test_with_single_tag"]["tags"] == {"team": "frontend"} | ||
| assert "tags" not in tests_by_name["test_without_tags"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.