Skip to content

Commit 128f0a9

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Fix test isolation and coverage for PyPy and macOS
1 parent 85410db commit 128f0a9

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/tests_and_coverage.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,20 @@ jobs:
6060
shell: bash
6161
run: pip list
6262

63-
- name: Run tests and show the branch coverage on the command line
63+
- name: Run tests and show the branch coverage on the command line (CPython)
64+
if: "!startsWith(matrix.python-version, 'pypy')"
65+
shell: bash
66+
run: |
67+
pth_file="$(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')/suby_coverage_process_startup.pth"
68+
printf "import os; os.getenv('COVERAGE_PROCESS_START') and __import__('coverage').process_startup()\n" > "$pth_file"
69+
coverage erase
70+
COVERAGE_PROCESS_START="$PWD/pyproject.toml" coverage run -m pytest -p no:cov -n auto --cache-clear --assert=plain
71+
coverage combine
72+
coverage report -m --fail-under=100 --omit='*tests*'
73+
coverage xml --omit='*tests*'
74+
75+
- name: Run tests and show the branch coverage on the command line (PyPy)
76+
if: startsWith(matrix.python-version, 'pypy')
6477
shell: bash
6578
run: pytest --cov=suby --cov-branch --cov-report=term-missing --cov-report=xml:coverage.xml --cov-fail-under=100 -n auto --cache-clear --assert=plain
6679

tests/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111

1212
def pytest_configure(config):
13-
"""Prevent child processes spawned by run() from inheriting pytest-cov's subprocess coverage.
13+
"""Prevent child processes spawned by run() from inheriting subprocess coverage hooks.
1414
15-
Without this, every short-lived Python subprocess spawned by the test suite inherits COV_CORE_*
16-
environment variables, causing pytest-cov's .pth hook to activate coverage in each child process.
15+
Without this, every short-lived Python subprocess spawned by the test suite inherits coverage
16+
environment variables (COVERAGE_PROCESS_START for coverage run, COV_CORE_* for pytest-cov),
17+
causing coverage to activate in each child process and slowing the suite significantly.
1718
"""
1819
if hasattr(config, 'workerinput'):
20+
os.environ.pop('COVERAGE_PROCESS_START', None)
1921
for key in list(os.environ):
2022
if key.startswith('COV_CORE_'):
2123
os.environ.pop(key)

tests/units/test_process_waiting.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
_is_event_driven_platform = has_event_driven_wait()
2828
_is_macos = sys.platform == 'darwin'
2929
_is_linux = sys.platform == 'linux'
30+
_is_pypy = sys.implementation.name == 'pypy'
3031
_has_pidfd = hasattr(os, 'pidfd_open')
3132
_COORDINATION_TIMEOUT_SECONDS = 5.0
3233

@@ -207,7 +208,7 @@ def test_oserror_fallback_with_reaped_pid():
207208
@pytest.mark.parametrize(
208209
'expected',
209210
[
210-
pytest.param(True, marks=pytest.mark.skipif(not _is_macos, reason='macOS only')),
211+
pytest.param(True, marks=pytest.mark.skipif(not _is_macos or _is_pypy, reason='macOS CPython only')),
211212
pytest.param(True, marks=pytest.mark.skipif(not (_is_linux and _has_pidfd), reason='Linux 3.9+ only')),
212213
pytest.param(False, marks=pytest.mark.skipif(_is_event_driven_platform, reason='Only for fallback platforms')),
213214
],
@@ -315,7 +316,7 @@ def worker():
315316
@pytest.mark.parametrize(
316317
'waiter_name',
317318
[
318-
pytest.param('_wait_kqueue', marks=pytest.mark.skipif(not _is_macos, reason='macOS only')),
319+
pytest.param('_wait_kqueue', marks=pytest.mark.skipif(not _is_macos or _is_pypy, reason='macOS CPython only')),
319320
pytest.param('_wait_pidfd', marks=pytest.mark.skipif(not (_is_linux and _has_pidfd), reason='Linux 3.9+ only')),
320321
],
321322
)
@@ -337,7 +338,7 @@ def test_platform_waiter_directly_returns_without_killing_running_process(waiter
337338
process.wait()
338339

339340

340-
@pytest.mark.skipif(not _is_macos, reason='macOS only')
341+
@pytest.mark.skipif(not _is_macos or _is_pypy, reason='macOS CPython only')
341342
def test_macos_wait_for_process_exit_passes_none_to_event_driven_waiter():
342343
"""On macOS, None timeout is forwarded to the event-driven waiter unchanged."""
343344
process = subprocess.Popen(
@@ -353,7 +354,7 @@ def test_macos_wait_for_process_exit_passes_none_to_event_driven_waiter():
353354
process.wait()
354355

355356

356-
@pytest.mark.skipif(not _is_macos, reason='macOS only')
357+
@pytest.mark.skipif(not _is_macos or _is_pypy, reason='macOS CPython only')
357358
def test_macos_wait_kqueue_builds_subscription_and_closes_queue():
358359
"""The macOS kqueue waiter subscribes to the child-process exit event and closes the kqueue handle afterwards."""
359360
mock_kqueue = MagicMock()
@@ -375,7 +376,7 @@ def test_macos_wait_kqueue_builds_subscription_and_closes_queue():
375376
mock_kqueue.close.assert_called_once()
376377

377378

378-
@pytest.mark.skipif(not _is_macos, reason='macOS only')
379+
@pytest.mark.skipif(not _is_macos or _is_pypy, reason='macOS CPython only')
379380
def test_macos_wait_for_process_exit_falls_back_after_kqueue_oserror():
380381
"""If the macOS waiter raises OSError, wait_for_process_exit falls back to process.wait()."""
381382
process = subprocess.Popen(

0 commit comments

Comments
 (0)