Skip to content

Commit

Permalink
fix: only use "sysmon" core when available (Python 3.12+) (#1747)
Browse files Browse the repository at this point in the history
* Only use sysmon core when available (Python 3.12+)

* Update test case for both with and without SysMonitor
  • Loading branch information
hugovk authored Feb 20, 2024
1 parent 575a44c commit 8b0e039
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions coverage/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def __init__(
core = "pytrace"
else:
core = os.getenv("COVERAGE_CORE")

if core == "sysmon" and not env.PYBEHAVIOR.pep669:
core = None

if not core:
# Once we're comfortable with sysmon as a default:
# if env.PYBEHAVIOR.pep669 and self.should_start_context is None:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,17 @@ def test_core_request_pytrace(self) -> None:
core = re_line(r" core:", out).strip()
assert core == "core: PyTracer"

@pytest.mark.skipif(not env.PYBEHAVIOR.pep669, reason="No sys.monitoring to request")
def test_core_request_sysmon(self) -> None:
self.del_environ("COVERAGE_TEST_CORES")
self.set_environ("COVERAGE_CORE", "sysmon")
self.make_file("numbers.py", "print(123, 456)")
out = self.run_command("coverage run --debug=sys numbers.py")
assert out.endswith("123 456\n")
core = re_line(r" core:", out).strip()
assert core == "core: SysMonitor"
if env.PYBEHAVIOR.pep669:
assert core == "core: SysMonitor"
else:
assert core in ("core: CTracer", "core: PyTracer")


class FailUnderNoFilesTest(CoverageTest):
Expand Down

0 comments on commit 8b0e039

Please sign in to comment.