Skip to content

Commit 874cc0b

Browse files
committed
test: adjust tests for the sysmon core
1 parent 7a7cb6a commit 874cc0b

10 files changed

+48
-14
lines changed

tests/test_cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ def test_version(self) -> None:
10081008
self.command_line("--version")
10091009
out = self.stdout()
10101010
assert "ersion " in out
1011-
if testenv.C_TRACER:
1011+
if testenv.C_TRACER or testenv.SYS_MON:
10121012
assert "with C extension" in out
10131013
else:
10141014
assert "without C extension" in out

tests/test_concurrency.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ def test_bug_890(self) -> None:
607607
assert out.splitlines()[-1] == "ok"
608608

609609

610+
@pytest.mark.skipif(not testenv.SETTRACE_CORE, reason="gettrace is not supported with this core.")
610611
def test_coverage_stop_in_threads() -> None:
611612
has_started_coverage = []
612613
has_stopped_coverage = []

tests/test_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
from typing import Any, List, Optional, Tuple
1212
from unittest import mock
1313

14+
import pytest
15+
1416
import coverage
1517
from coverage.context import qualname_from_frame
1618
from coverage.data import CoverageData, sorted_lines
1719
from coverage.types import TArc, TCovKwargs, TLineNo
1820

21+
from tests import testenv
1922
from tests.coveragetest import CoverageTest
2023
from tests.helpers import assert_count_equal
2124

@@ -124,6 +127,7 @@ def assert_combined_arcs(filename: str, context: str, lines: List[TArc]) -> None
124127
assert_combined_arcs(fblue, 'blue', self.ARCS)
125128

126129

130+
@pytest.mark.skipif(not testenv.DYN_CONTEXTS, reason="No dynamic contexts with this core")
127131
class DynamicContextTest(CoverageTest):
128132
"""Tests of dynamically changing contexts."""
129133

tests/test_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_debug_sys(self) -> None:
197197
def test_debug_sys_ctracer(self) -> None:
198198
out_text = self.f1_debug_output(["sys"])
199199
tracer_line = re_line(r"CTracer:", out_text).strip()
200-
if testenv.C_TRACER:
200+
if testenv.C_TRACER or testenv.SYS_MON:
201201
expected = "CTracer: available"
202202
else:
203203
expected = "CTracer: unavailable"

tests/test_html.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from coverage.report_core import get_analysis_to_report
2828
from coverage.types import TLineNo, TMorf
2929

30+
from tests import testenv
3031
from tests.coveragetest import CoverageTest, TESTS_DIR
3132
from tests.goldtest import gold_path
3233
from tests.goldtest import compare, contains, contains_rx, doesnt_contain, contains_any
@@ -1135,6 +1136,7 @@ def test_accented_directory(self) -> None:
11351136
assert expected % os.sep in index
11361137

11371138

1139+
@pytest.mark.skipif(not testenv.DYN_CONTEXTS, reason="No dynamic contexts with this core.")
11381140
class HtmlWithContextsTest(HtmlTestHelpers, CoverageTest):
11391141
"""Tests of the HTML reports with shown contexts."""
11401142

tests/test_oddball.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,21 +474,25 @@ def swap_it():
474474

475475
def test_setting_new_trace_function(self) -> None:
476476
# https://github.com/nedbat/coveragepy/issues/436
477+
if testenv.SETTRACE_CORE:
478+
missing = "5-7, 13-14"
479+
else:
480+
missing = "5-7"
477481
self.check_coverage('''\
478482
import os.path
479483
import sys
480484
481485
def tracer(frame, event, arg):
482-
filename = os.path.basename(frame.f_code.co_filename)
483-
print(f"{event}: {filename} @ {frame.f_lineno}")
484-
return tracer
486+
filename = os.path.basename(frame.f_code.co_filename) # 5
487+
print(f"{event}: {filename} @ {frame.f_lineno}") # 6
488+
return tracer # 7
485489
486490
def begin():
487491
sys.settrace(tracer)
488492
489493
def collect():
490-
t = sys.gettrace()
491-
assert t is tracer, t
494+
t = sys.gettrace() # 13
495+
assert t is tracer, t # 14
492496
493497
def test_unsets_trace() -> None:
494498
begin()
@@ -501,7 +505,7 @@ def test_unsets_trace() -> None:
501505
b = 22
502506
''',
503507
lines=[1, 2, 4, 5, 6, 7, 9, 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 23, 24],
504-
missing="5-7, 13-14",
508+
missing=missing,
505509
)
506510

507511
assert self.last_module_name is not None

tests/test_plugins.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def coverage_init(reg, options):
207207
cov._debug_file = debug_out
208208
cov.set_option("run:plugins", ["plugin_sys_info"])
209209
with swallow_warnings(
210-
r"Plugin file tracers \(plugin_sys_info.Plugin\) aren't supported with PyTracer"
210+
r"Plugin file tracers \(plugin_sys_info.Plugin\) aren't supported with .*"
211211
):
212212
cov.start()
213213
cov.stop() # pragma: nested
@@ -273,23 +273,28 @@ def coverage_init(reg, options):
273273
assert out == ""
274274

275275

276-
@pytest.mark.skipif(testenv.C_TRACER, reason="This test is only about PyTracer.")
276+
@pytest.mark.skipif(testenv.PLUGINS, reason="This core doesn't support plugins.")
277277
class PluginWarningOnPyTracerTest(CoverageTest):
278-
"""Test that we get a controlled exception with plugins on PyTracer."""
278+
"""Test that we get a controlled exception when plugins aren't supported."""
279279
def test_exception_if_plugins_on_pytracer(self) -> None:
280280
self.make_file("simple.py", "a = 1")
281281

282282
cov = coverage.Coverage()
283283
cov.set_option("run:plugins", ["tests.plugin1"])
284284

285+
if testenv.PY_TRACER:
286+
core = "PyTracer"
287+
elif testenv.SYS_MON:
288+
core = "Pep669Tracer"
289+
285290
expected_warnings = [
286-
r"Plugin file tracers \(tests.plugin1.Plugin\) aren't supported with PyTracer",
291+
fr"Plugin file tracers \(tests.plugin1.Plugin\) aren't supported with {core}",
287292
]
288293
with self.assert_warnings(cov, expected_warnings):
289294
self.start_import_stop(cov, "simple")
290295

291296

292-
@pytest.mark.skipif(not testenv.C_TRACER, reason="Plugins are only supported with the C tracer.")
297+
@pytest.mark.skipif(not testenv.PLUGINS, reason="Plugins are not supported with this core.")
293298
class FileTracerTest(CoverageTest):
294299
"""Tests of plugins that implement file_tracer."""
295300

@@ -962,6 +967,7 @@ def test_configurer_plugin(self) -> None:
962967
assert "pragma: or whatever" in excluded
963968

964969

970+
@pytest.mark.skipif(not testenv.DYN_CONTEXTS, reason="No dynamic contexts with this core")
965971
class DynamicContextPluginTest(CoverageTest):
966972
"""Tests of plugins that implement `dynamic_context`."""
967973

tests/test_process.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ def test_timid(self) -> None:
539539
# If the C trace function is being tested, then regular running should have
540540
# the C function, which registers itself as f_trace.
541541
assert cov_out == "CTracer\n"
542+
elif testenv.SYS_MON:
543+
assert cov_out == "None\n"
542544
else:
543545
# If the Python trace function is being tested, then regular running will
544546
# also show the Python function.

tests/test_venv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_venv_isnt_measured(self, coverage_command: str) -> None:
283283
assert "coverage" not in out
284284
assert "colorsys" not in out
285285

286-
@pytest.mark.skipif(not testenv.C_TRACER, reason="Plugins are only supported with the C tracer.")
286+
@pytest.mark.skipif(not testenv.C_TRACER, reason="No plugins with this core.")
287287
def test_venv_with_dynamic_plugin(self, coverage_command: str) -> None:
288288
# https://github.com/nedbat/coveragepy/issues/1150
289289
# Django coverage plugin was incorrectly getting warnings:

tests/testenv.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@
99

1010
# Are we testing the C-implemented trace function?
1111
C_TRACER = os.getenv("COVERAGE_CORE", "ctrace") == "ctrace"
12+
13+
# Are we testing the Python-implemented trace function?
14+
PY_TRACER = os.getenv("COVERAGE_CORE", "ctrace") == "pytrace"
15+
16+
# Are we testing the sys.monitoring implementation?
17+
SYS_MON = os.getenv("COVERAGE_CORE", "ctrace") == "sysmon"
18+
19+
# Are we using a settrace function as a core?
20+
SETTRACE_CORE = C_TRACER or PY_TRACER
21+
22+
# Are plugins supported during these tests?
23+
PLUGINS = C_TRACER
24+
25+
# Are dynamic contexts supported during these tests?
26+
DYN_CONTEXTS = C_TRACER or PY_TRACER

0 commit comments

Comments
 (0)