Skip to content

Commit 356d355

Browse files
committed
Merge PR aio-libs#13422 from branch 'testing/coverage-sync-modern-sdist-install'
2 parents 8aac7bf + c1b13b4 commit 356d355

7 files changed

Lines changed: 196 additions & 52 deletions

File tree

.coveragerc-cython.toml

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,81 @@
1-
[run]
2-
branch = true
3-
plugins = [
4-
'Cython.Coverage',
5-
]
6-
omit = [
7-
'site-packages',
1+
[html]
2+
show_contexts = true
3+
skip_covered = false
4+
5+
[paths]
6+
_site-packages-to-src-mapping = [
7+
'.',
8+
'*/lib/pypy*/site-packages',
9+
'*/lib/python*/site-packages',
10+
'*\Lib\site-packages',
811
]
912

1013
[report]
11-
partial_also = [
12-
'if not TYPE_CHECKING',
13-
]
1414
exclude_also = [
1515
'if TYPE_CHECKING',
1616
'assert False',
1717
': \.\.\.(\s*#.*)?$',
1818
'^ +\.\.\.$',
19-
'pytest.fail\('
19+
'pytest.fail\(',
20+
# '^\s*@pytest\.mark\.xfail', # important for Dreamsorcerer
21+
]
22+
# fail_under = 100
23+
partial_also = [
24+
'if not TYPE_CHECKING',
25+
]
26+
show_missing = true
27+
skip_covered = true
28+
skip_empty = true
29+
30+
[run]
31+
branch = true
32+
# NOTE: `ctrace` tracing method is needed because the `sysmon` tracer
33+
# NOTE: which is default on Python 3.14, causes unprecedented slow-down
34+
# NOTE: of the test runs. Also, Cython the `Cython.Coverage` plugin does
35+
# NOTE: not support `sysmon`.
36+
# Ref: https://github.com/coveragepy/coveragepy/issues/2099
37+
core = 'ctrace'
38+
cover_pylib = false
39+
# NOTE: `disable_warnings` is needed when `pytest-cov` runs in tandem
40+
# NOTE: with `pytest-xdist`. These warnings are false negative in this
41+
# NOTE: context.
42+
#
43+
# NOTE: It's `coveragepy` that emits the warnings and previously they
44+
# NOTE: wouldn't get on the radar of `pytest`'s `filterwarnings`
45+
# NOTE: mechanism. This changed, however, with `pytest >= 8.4`. And
46+
# NOTE: since we set `filterwarnings = error`, those warnings are being
47+
# NOTE: raised as exceptions, cascading into `pytest`'s internals and
48+
# NOTE: causing tracebacks and crashes of the test sessions.
49+
#
50+
# Ref:
51+
# * https://github.com/pytest-dev/pytest-cov/issues/693
52+
# * https://github.com/pytest-dev/pytest-cov/pull/695
53+
# * https://github.com/pytest-dev/pytest-cov/pull/696
54+
disable_warnings = [
55+
'module-not-measured',
56+
]
57+
# https://coverage.rtfd.io/en/latest/contexts.html#dynamic-contexts
58+
# dynamic_context = 'test_function' # conflicts with `pytest-cov` if set here
59+
omit = [
60+
'setup.py',
61+
]
62+
# NOTE: tests/autobahn/test_autobahn.py::test_{client,server}
63+
# NOTE: pass `-a|--append` to `coverage run` wich conflicts
64+
# NOTE: with `-p|--parallel-mode`. We cannot override it on
65+
# NOTE: the CLI level, but instead define an environment
66+
# NOTE: variable to implement this.
67+
#
68+
# Refs:
69+
# * https://discord.com/channels/267624335836053506/1253355750684753950/1537906072474488973
70+
# * https://discord.com/channels/267624335836053506/1253355750684753950/1537914331629486130
71+
parallel = '${COVERAGE_PARALLEL_MODE-true}'
72+
plugins = [
73+
'Cython.Coverage',
74+
]
75+
relative_files = true
76+
source = [
77+
'.',
78+
]
79+
source_pkgs = [
80+
'aiohttp',
2081
]

.coveragerc.toml

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,81 @@
1+
[html]
2+
show_contexts = true
3+
skip_covered = false
4+
5+
[paths]
6+
_site-packages-to-src-mapping = [
7+
'.',
8+
'*/lib/pypy*/site-packages',
9+
'*/lib/python*/site-packages',
10+
'*\Lib\site-packages',
11+
]
12+
13+
[report]
14+
exclude_also = [
15+
'if TYPE_CHECKING',
16+
'assert False',
17+
': \.\.\.(\s*#.*)?$',
18+
'^ +\.\.\.$',
19+
'pytest.fail\(',
20+
# '^\s*@pytest\.mark\.xfail', # important for Dreamsorcerer
21+
]
22+
# fail_under = 100
23+
partial_also = [
24+
'if not TYPE_CHECKING',
25+
]
26+
show_missing = true
27+
skip_covered = true
28+
skip_empty = true
29+
130
[run]
231
branch = true
332
# NOTE: `ctrace` tracing method is needed because the `sysmon` tracer
433
# NOTE: which is default on Python 3.14, causes unprecedented slow-down
5-
# NOTE: of the test runs.
34+
# NOTE: of the test runs. Also, Cython the `Cython.Coverage` plugin does
35+
# NOTE: not support `sysmon`.
636
# Ref: https://github.com/coveragepy/coveragepy/issues/2099
737
core = 'ctrace'
8-
source = [
9-
'aiohttp',
10-
'tests',
38+
cover_pylib = false
39+
# NOTE: `disable_warnings` is needed when `pytest-cov` runs in tandem
40+
# NOTE: with `pytest-xdist`. These warnings are false negative in this
41+
# NOTE: context.
42+
#
43+
# NOTE: It's `coveragepy` that emits the warnings and previously they
44+
# NOTE: wouldn't get on the radar of `pytest`'s `filterwarnings`
45+
# NOTE: mechanism. This changed, however, with `pytest >= 8.4`. And
46+
# NOTE: since we set `filterwarnings = error`, those warnings are being
47+
# NOTE: raised as exceptions, cascading into `pytest`'s internals and
48+
# NOTE: causing tracebacks and crashes of the test sessions.
49+
#
50+
# Ref:
51+
# * https://github.com/pytest-dev/pytest-cov/issues/693
52+
# * https://github.com/pytest-dev/pytest-cov/pull/695
53+
# * https://github.com/pytest-dev/pytest-cov/pull/696
54+
disable_warnings = [
55+
'module-not-measured',
1156
]
57+
# https://coverage.rtfd.io/en/latest/contexts.html#dynamic-contexts
58+
# dynamic_context = 'test_function' # conflicts with `pytest-cov` if set here
1259
omit = [
13-
'site-packages',
60+
'setup.py',
1461
]
15-
16-
[report]
17-
partial_also = [
18-
'if not TYPE_CHECKING',
62+
# NOTE: tests/autobahn/test_autobahn.py::test_{client,server}
63+
# NOTE: pass `-a|--append` to `coverage run` wich conflicts
64+
# NOTE: with `-p|--parallel-mode`. We cannot override it on
65+
# NOTE: the CLI level, but instead define an environment
66+
# NOTE: variable to implement this.
67+
#
68+
# Refs:
69+
# * https://discord.com/channels/267624335836053506/1253355750684753950/1537906072474488973
70+
# * https://discord.com/channels/267624335836053506/1253355750684753950/1537914331629486130
71+
parallel = '${COVERAGE_PARALLEL_MODE-true}'
72+
# plugins = [
73+
# 'covdefaults',
74+
# ]
75+
relative_files = true
76+
source = [
77+
'.',
1978
]
20-
exclude_also = [
21-
'if TYPE_CHECKING',
22-
'assert False',
23-
': \.\.\.(\s*#.*)?$',
24-
'^ +\.\.\.$',
25-
'pytest.fail\('
79+
source_pkgs = [
80+
'aiohttp',
2681
]

.github/workflows/ci-cd.yml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ jobs:
317317
AIOHTTP_NO_EXTENSIONS: ${{ matrix.no-extensions }}
318318
PIP_USER: 1
319319
run: >-
320-
pytest --junitxml=junit.xml --numprocesses=auto --cov=aiohttp/ --cov=tests/ -m 'not dev_mode and not autobahn'
320+
pytest --junitxml=junit.xml --numprocesses=auto --cov -m 'not dev_mode and not autobahn'
321321
shell: bash
322322
- name: Re-run the failing tests with maximum verbosity
323323
if: failure()
@@ -333,14 +333,8 @@ jobs:
333333
AIOHTTP_NO_EXTENSIONS: ${{ matrix.no-extensions }}
334334
PIP_USER: 1
335335
PYTHONDEVMODE: 1
336-
run: pytest -m dev_mode --cov=aiohttp/ --cov=tests/ --cov-append
336+
run: pytest -m dev_mode --cov --cov-append --cov-report=xml
337337
shell: bash
338-
- name: Turn coverage into xml
339-
env:
340-
COLOR: 'yes'
341-
PIP_USER: 1
342-
run: |
343-
python -m coverage xml
344338
- name: Upload coverage
345339
uses: codecov/codecov-action@v7
346340
with:
@@ -474,14 +468,9 @@ jobs:
474468
PIP_USER: 1
475469
run: >-
476470
PATH="${HOME}/Library/Python/3.11/bin:${HOME}/.local/bin:${PATH}"
477-
pytest --junitxml=junit.xml --cov=aiohttp/ --cov=tests/ --timeout=0 -m autobahn
471+
pytest --junitxml=junit.xml --cov --cov-report=xml
472+
--timeout=0 -m autobahn
478473
shell: bash
479-
- name: Turn coverage into xml
480-
env:
481-
COLOR: 'yes'
482-
PIP_USER: 1
483-
run: |
484-
python -m coverage xml
485474
- name: Upload coverage
486475
uses: codecov/codecov-action@v7
487476
with:
@@ -596,12 +585,11 @@ jobs:
596585
PIP_USER: 1
597586
run: >-
598587
pytest tests/test_client_functional.py tests/test_http_parser.py tests/test_http_writer.py tests/test_web_functional.py tests/test_web_response.py tests/test_websocket_parser.py
599-
--cov-config=.coveragerc-cython.toml --cov=aiohttp/ --cov=tests/ --numprocesses=auto
588+
--cov-config=.coveragerc-cython.toml --cov
589+
--cov-report=xml:cython-coverage.xml
590+
--numprocesses=auto
600591
-m 'not dev_mode and not autobahn'
601592
shell: bash
602-
- name: Turn coverage into xml
603-
run: |
604-
python -m coverage xml -o cython-coverage.xml --rcfile=.coveragerc-cython.toml
605593
- name: Upload coverage
606594
uses: codecov/codecov-action@v7
607595
with:

CHANGES/13422.contrib.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Synchronized the ``coverage.py`` configuration (:file:`.coveragerc.toml` and
2+
:file:`.coveragerc-cython.toml`) with the pattern already established in
3+
:external+yarl:doc:`yarl <index>`, :external+multidict:doc:`multidict
4+
<index>`, ``frozenlist`` and other sibling projects
5+
-- by :user:`webknjaz`.
6+
7+
Both files now anchor package discovery through ``source_pkgs`` instead of
8+
relying on a same-named directory happening to exist relative to the
9+
working directory, and add a ``[paths]`` mapping so coverage recorded
10+
against an installed copy of ``aiohttp`` still combines correctly with
11+
coverage recorded from the Git checkout. CI now lets ``pytest-cov`` write
12+
``coverage.xml`` directly via ``--cov-report=xml`` instead of a separate
13+
``coverage xml`` step, and the Autobahn testsuite's subprocess-based
14+
coverage collection (which uses ``coverage run --append``, incompatible
15+
with parallel mode) now opts out per-invocation via a
16+
``COVERAGE_PARALLEL_MODE`` environment variable instead of trying to
17+
override it on the command line.

docs/spelling_wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ subclasses
343343
subdirectory
344344
submodules
345345
subpackage
346+
subprocess
346347
subprotocol
347348
subprotocols
348349
subtype
@@ -359,6 +360,7 @@ TCP
359360
teardown
360361
Teardown
361362
TestClient
363+
testsuite
362364
Testsuite
363365
Tf
364366
timestamps

setup.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ combine_as_imports=True
3434
known_third_party=jinja2,pytest,multidict,yarl,gunicorn,freezegun
3535
known_first_party=aiohttp,aiohttp_jinja2,aiopg
3636

37-
[report]
38-
exclude_lines =
39-
@abc.abstractmethod
40-
@abstractmethod
41-
4237
[tool:pytest]
4338
addopts =
4439
# show 10 slowest invocations:

tests/autobahn/test_autobahn.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
import os
23
import pprint
34
import socket
45
import subprocess
6+
import sys
57
import time
68
from collections.abc import Iterator
79
from pathlib import Path
@@ -103,7 +105,20 @@ def test_client(report_dir: Path, request: pytest.FixtureRequest) -> None:
103105
)
104106
try:
105107
wait_for_port(9001)
106-
subprocess.run(("coverage", "run", "-a", "tests/autobahn/client/client.py"))
108+
subprocess.run(
109+
(
110+
sys.executable,
111+
"-m",
112+
"coverage",
113+
"run",
114+
"--append",
115+
"tests/autobahn/client/client.py",
116+
),
117+
env={
118+
"COVERAGE_PARALLEL_MODE": "false",
119+
**os.environ.copy(),
120+
},
121+
)
107122
finally:
108123
autobahn_container.stop()
109124

@@ -141,7 +156,18 @@ def test_client(report_dir: Path, request: pytest.FixtureRequest) -> None:
141156
@pytest.mark.autobahn
142157
def test_server(report_dir: Path, request: pytest.FixtureRequest) -> None:
143158
server = subprocess.Popen(
144-
("coverage", "run", "-a", "tests/autobahn/server/server.py")
159+
(
160+
sys.executable,
161+
"-m",
162+
"coverage",
163+
"run",
164+
"--append",
165+
"tests/autobahn/server/server.py",
166+
),
167+
env={
168+
"COVERAGE_PARALLEL_MODE": "false",
169+
**os.environ.copy(),
170+
},
145171
)
146172
try:
147173
wait_for_port(9001)

0 commit comments

Comments
 (0)