diff --git a/.coveragerc b/.coveragerc index 5d3f57aa66..98f923bd8e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/ci.sh b/ci.sh index d306212f70..ed97ff738b 100755 --- a/ci.sh +++ b/ci.sh @@ -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 diff --git a/test-requirements.in b/test-requirements.in index 0227daef6a..fc94889d91 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -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 diff --git a/test-requirements.txt b/test-requirements.txt index 719617a34b..f96eb2f32a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 @@ -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 @@ -134,7 +130,6 @@ tomli==2.0.1 # via # black # build - # coverage # mypy # pylint # pytest diff --git a/trio/_core/_tests/test_multierror.py b/trio/_core/_tests/test_multierror.py index 7d31b1e889..fc4a5a6637 100644 --- a/trio/_core/_tests/test_multierror.py +++ b/trio/_core/_tests/test_multierror.py @@ -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, diff --git a/trio/_core/_tests/test_multierror_scripts/apport_excepthook.py b/trio/_core/_tests/test_multierror_scripts/apport_excepthook.py index 12e7fb0851..b5b2e16c8e 100644 --- a/trio/_core/_tests/test_multierror_scripts/apport_excepthook.py +++ b/trio/_core/_tests/test_multierror_scripts/apport_excepthook.py @@ -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.