Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-110722: Make -m test -T -j use sys.monitoring#111710
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
9611b56bf65fbe1adbf57d4f5b6b84263a33a0688baa31295File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """A minimal hook for gathering line coverage of the standard library. | ||
| Designed to be used with -Xpresite= which means: | ||
| * it installs itself on import | ||
| * it's not imported as `__main__` so can't use the ifmain idiom | ||
| * it can't import anything besides `sys` to avoid tainting gathered coverage | ||
| * filenames are not normalized | ||
| To get gathered coverage back, look for 'test.cov' in `sys.modules` | ||
| instead of importing directly. That way you can determine if the module | ||
| was already in use. | ||
| If you need to disable the hook, call the `disable()` function. | ||
| """ | ||
| import sys | ||
ambv marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| mon = sys.monitoring | ||
ambv marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| FileName = str | ||
| LineNo = int | ||
| Location = tuple[FileName, LineNo] | ||
| coverage: set[Location] = set() | ||
| # `types` and `typing` aren't imported to avoid invalid coverage | ||
| def add_line( | ||
| code: "types.CodeType", | ||
| lineno: int, | ||
| ) -> "typing.Literal[sys.monitoring.DISABLE]": | ||
ambv marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| coverage.add((code.co_filename, lineno)) | ||
| return mon.DISABLE | ||
| def enable(): | ||
| mon.use_tool_id(mon.COVERAGE_ID, "regrtest coverage") | ||
| mon.register_callback(mon.COVERAGE_ID, mon.events.LINE, add_line) | ||
| mon.set_events(mon.COVERAGE_ID, mon.events.LINE) | ||
| def disable(): | ||
| mon.set_events(mon.COVERAGE_ID, 0) | ||
| mon.register_callback(mon.COVERAGE_ID, mon.events.LINE, None) | ||
| mon.free_tool_id(mon.COVERAGE_ID) | ||
| enable() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -78,6 +78,11 @@ def must_stop(state): | ||
| } | ||
| FileName = str | ||
| LineNo = int | ||
| Location = tuple[FileName, LineNo] | ||
ambv marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @dataclasses.dataclass(slots=True) | ||
| class TestResult: | ||
| test_name: TestName | ||
| @@ -91,6 +96,9 @@ class TestResult: | ||
| errors: list[tuple[str, str]] | None = None | ||
| failures: list[tuple[str, str]] | None = None | ||
| # partial coverage in a worker run; not used by sequential in-process runs | ||
| covered_lines: list[Location] | None = None | ||
| def is_failed(self, fail_env_changed: bool) -> bool: | ||
| if self.state == State.ENV_CHANGED: | ||
| return fail_env_changed | ||
| @@ -207,6 +215,10 @@ def _decode_test_result(data: dict[str, Any]) -> TestResult | dict[str, Any]: | ||
| data.pop('__test_result__') | ||
| if data['stats'] is not None: | ||
| data['stats'] = TestStats(**data['stats']) | ||
| if data['covered_lines'] is not None: | ||
| data['covered_lines'] = [ | ||
| tuple(loc) for loc in data['covered_lines'] | ||
| ] | ||
| return TestResult(**data) | ||
| else: | ||
| return data | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.