Skip to content

Commit

Permalink
Fix coverage capture
Browse files Browse the repository at this point in the history
- Move build/install into the test methods to reduce coupling with
  tox.ini
- Add the missing COVERAGE_PROCESS_START environment variable
- Move -p (parallel) to the config file
- When combining, pull coverage from the example directories because the
  package build process uses them as a working directory
  • Loading branch information
twm committed Jul 7, 2024
1 parent 690994e commit 799b7f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source_pkgs = incremental
# List of directory names.
source = tests
branch = True
parallel = True

[paths]
source =
Expand Down
22 changes: 21 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,33 @@
Tests for the packaging examples.
"""

from twisted.trial.unittest import TestCase
import os
from importlib import metadata
from subprocess import run

from build import ProjectBuilder
from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase


TEST_DIR = FilePath(os.path.abspath(os.path.dirname(__file__)))


def build_and_install(path): # type: (FilePath) -> None
builder = ProjectBuilder(path.path)
pkgfile = builder.build("wheel", output_directory=os.environ["PIP_FIND_LINKS"])

# Force reinstall in case tox reused the venv.
run(["pip", "install", "--force-reinstall", pkgfile], check=True)


class ExampleTests(TestCase):
def test_setuppy_version(self):
"""
example_setuppy has a version of 1.2.3.
"""
build_and_install(TEST_DIR.child("example_setuppy"))

import example_setuppy

self.assertEqual(example_setuppy.__version__.base(), "1.2.3")
Expand All @@ -23,6 +41,8 @@ def test_setuptools_version(self):
"""
example_setuptools has a version of 2.3.4.
"""
build_and_install(TEST_DIR.child("example_setuptools"))

import example_setuptools

self.assertEqual(example_setuptools.__version__.base(), "2.3.4")
Expand Down
11 changes: 6 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ envlist =
wheel = true
wheel_build_env = build
deps =
tests: build
tests: coverage
tests: coverage-p
tests,mypy: twisted
Expand All @@ -27,6 +28,8 @@ extras =
setenv =
; Suppress pointless chatter in the output.
PIP_DISABLE_PIP_VERSION_CHECK=yes
tests: PIP_FIND_LINKS={distdir}
tests: COVERAGE_PROCESS_START={toxinidir}/.coveragerc

commands =
python -V
Expand All @@ -38,11 +41,9 @@ commands =
tests: coverage --version
tests: {envbindir}/trial --version
tests: coverage erase
tests: coverage run -p {envbindir}/trial incremental
tests: coverage run -p -m pip install --use-pep517 --find-links {distdir} ./tests/example_setuppy
tests: coverage run -p -m pip -vvv install --use-pep517 --find-links {distdir} ./tests/example_setuptools
tests: coverage run -p {envbindir}/trial tests/test_examples.py
tests: coverage combine
tests: coverage run {envbindir}/trial incremental
tests: coverage run {envbindir}/trial tests/test_examples.py
tests: coverage combine . tests/example_setuppy tests/example_setuptools
tests: coverage report
tests: coverage html
tests: coverage xml
Expand Down

0 comments on commit 799b7f1

Please sign in to comment.