Skip to content

Commit ffb0998

Browse files
committed
GH-49397: [Python] Fix PYARROW_GENERATE_COVERAGE end-to-end flow
- Add pytest_configure hook in conftest.py to activate Cython.Coverage plugin before any pyarrow modules are imported - Complete .coveragerc with source, branch, report and html sections Closes: #49397
1 parent dbbf7cf commit ffb0998

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

python/.coveragerc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@
1717

1818
[run]
1919
plugins = Cython.Coverage
20+
source =
21+
pyarrow
22+
branch = True
23+
24+
[report]
25+
omit =
26+
*/tests/*
27+
*/benchmarks/*
28+
show_missing = True
29+
30+
[html]
31+
directory = coverage_html_report

python/pyarrow/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@
1818
import pytest
1919

2020
import os
21+
def pytest_configure(config):
22+
"""Activate the Cython coverage plugin when PYARROW_GENERATE_COVERAGE is set.
23+
24+
This must run before any pyarrow modules are imported so that the
25+
Cython line-tracing hooks embedded at build time are picked up by
26+
coverage.py. The flag is set by building pyarrow with
27+
PYARROW_GENERATE_COVERAGE=1 (see CMakeLists.txt).
28+
"""
29+
if os.environ.get("PYARROW_GENERATE_COVERAGE"):
30+
try:
31+
import Cython.Coverage # noqa: F401
32+
import coverage
33+
coverage.process_startup()
34+
except ImportError as e:
35+
import warnings
36+
warnings.warn(
37+
f"PYARROW_GENERATE_COVERAGE is set but required package "
38+
f"is not available: {e}. Install it with: "
39+
f"pip install coverage Cython",
40+
stacklevel=1,
41+
)
2142
import pyarrow as pa
2243
from pyarrow import Codec
2344
from pyarrow import fs

0 commit comments

Comments
 (0)