Skip to content

Commit

Permalink
Try out coverage instead of pytest-cov (#2665)
Browse files Browse the repository at this point in the history
* Use coverage instead of pytest-cov

---------

Co-authored-by: John Litborn <11260241+jakkdl@users.noreply.github.com>
  • Loading branch information
A5rocks and jakkdl authored Jun 28, 2023
1 parent 61775d5 commit afd51d1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[run]
branch=True
source=trio
# For some reason coverage recording doesn't work for ipython_custom_exc.py,
# so leave it out of reports
omit=
setup.py
*/ipython_custom_exc.py
# These are run in subprocesses, but still don't work. We follow
# coverage's documentation to no avail.
*/trio/_core/_tests/test_multierror_scripts/*
# Omit the generated files in trio/_core starting with _generated_
*/trio/_core/_generated_*
# script used to check type completeness that isn't run in tests
# Script used to check type completeness that isn't run in tests
*/trio/_tests/check_type_completeness.py
# The test suite spawns subprocesses to test some stuff, so make sure
# this doesn't corrupt the coverage files
Expand Down
9 changes: 8 additions & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,19 @@ else
# get mypy tests a nice cache
MYPYPATH=".." mypy --config-file= --cache-dir=./.mypy_cache -c "import trio" >/dev/null 2>/dev/null || true

if pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --cov="$INSTALLDIR" --cov-report=xml --cov-config=../.coveragerc --verbose; then
# support subprocess spawning with coverage.py
echo "import coverage; coverage.process_startup()" | tee -a "$INSTALLDIR/../sitecustomize.py"

if COVERAGE_PROCESS_START=$(pwd)/../.coveragerc coverage run --rcfile=../.coveragerc -m pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --verbose; then
PASSED=true
else
PASSED=false
fi

coverage combine --rcfile ../.coveragerc
coverage report -m --rcfile ../.coveragerc
coverage xml --rcfile ../.coveragerc

# Remove the LSP again; again we want to do this ASAP to avoid
# accidentally breaking other stuff.
if [ "$LSP" != "" ]; then
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# For tests
pytest >= 5.0 # for faulthandler in core
pytest-cov >= 2.6.0
coverage >= 7.2.5
async_generator >= 1.9
pyright
# ipython 7.x is the last major version supporting Python 3.7
Expand Down
9 changes: 2 additions & 7 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ click==8.1.3
# via
# black
# pip-tools
coverage[toml]==7.2.7
# via pytest-cov
coverage==7.2.7
# via -r test-requirements.in
cryptography==39.0.2
# via
# -r test-requirements.in
Expand Down Expand Up @@ -121,10 +121,6 @@ pyproject-hooks==1.0.0
pyright==1.1.310
# via -r test-requirements.in
pytest==7.3.1
# via
# -r test-requirements.in
# pytest-cov
pytest-cov==4.1.0
# via -r test-requirements.in
sniffio==1.3.0
# via -r test-requirements.in
Expand All @@ -134,7 +130,6 @@ tomli==2.0.1
# via
# black
# build
# coverage
# mypy
# pylint
# pytest
Expand Down
6 changes: 5 additions & 1 deletion trio/_core/_tests/test_multierror.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ def run_script(name, use_ipython=False):
print("subprocess PYTHONPATH:", env.get("PYTHONPATH"))

if use_ipython:
lines = [script_path.read_text(), "exit()"]
lines = [
"import runpy",
f"runpy.run_path(r'{script_path}', run_name='trio.fake')",
"exit()",
]

cmd = [
sys.executable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _common

# The apport_python_hook package is only installed as part of Ubuntu's system
# python, and not available in venvs. So before we can import it we have to
# make sure it's on sys.path.
Expand Down

0 comments on commit afd51d1

Please sign in to comment.