Skip to content

ENH: New spin coverage command#316

Open
ganesh-k13 wants to merge 3 commits intoscientific-python:mainfrom
ganesh-k13:coverage_cmd
Open

ENH: New spin coverage command#316
ganesh-k13 wants to merge 3 commits intoscientific-python:mainfrom
ganesh-k13:coverage_cmd

Conversation

@ganesh-k13
Copy link
Contributor

New spin coverage command

spin coverage --help
Usage: spin coverage [OPTIONS]
                     [PYTEST_ARGS]...

  📊 Run tests with Python code coverage

  Generate coverage reports using pytest-cov. By default, a terminal report is printed. Supports any report type
  that pytest-cov supports.

  For file-based reports, use the `type:path` format. Relative paths are placed under `build/coverage/`.

  To generate an HTML report:

    spin coverage --cov-report html:htmlcov

  Multiple report types can be specified:

    spin coverage --cov-report term-missing --cov-report xml:coverage.xml

  Run coverage on specific tests:

    spin coverage -t example_pkg.echo
    spin coverage example_pkg/tests

  Pass additional pytest arguments after `--`:

    spin coverage -- --durations=10 -k "test_foo"

  Run tests in parallel (requires pytest-xdist):

    spin coverage -j auto

Options:
  -j N_JOBS                  Number of parallel jobs for testing with pytest-xdist.  [default: 1]
  -t, --tests TESTS          Which tests to run. Can be a module, function, class, or method.
  -v, --verbose              
  --cov-report TYPE          Coverage report type passed to pytest-cov (e.g. term, term-missing, html:dir,
                             xml:file.xml, json:file.json, lcov:file.lcov, annotate:dir). Can be specified
                             multiple times. Defaults to `term`.
  --no-build                 Disable building before executing command
  -C, --build-dir BUILD_DIR  Meson build directory; package is installed into './{build-dir}-install'.  [env
                             var: SPIN_BUILD_DIR; default: build]
  --help                     Show this message and exit.

Examples

spin coverage --cov-report=markdown:cov.md                     
Invoking `build` prior to running tests:
...
============================================== test session starts ===============================================
platform darwin -- Python 3.13.5, pytest-9.0.2, pluggy-1.5.0
rootdir: /<>/Documents/os/devpy
configfile: pyproject.toml
plugins: anyio-4.9.0, xdist-3.8.0, timeout-2.4.0, scipy_doctest-2.1.0, hypothesis-6.151.3, cov-7.0.0
collected 2 items                                                                                                

example_pkg/submodule/tests/test_submodule.py .                                                            [ 50%]
example_pkg/tests/test_core.py .                                                                           [100%]

================================================= tests coverage =================================================
________________________________ coverage: platform darwin, python 3.13.5-final-0 ________________________________

Coverage Markdown information written to file /<>/os/devpy/example_pkg/build/coverage/cov.md
=============================================== 2 passed in 0.20s ================================================
hello world

Notes

if verbose:
pytest_args = ("-v",) + pytest_args

if coverage:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this PR is ok, we might want to deprecate this

@stefanv
Copy link
Member

stefanv commented Mar 3, 2026

We already have --gcov and --coverage flags for the test command. Does it make sense to separate coverage out?

@ganesh-k13
Copy link
Contributor Author

Yes that's the same question I have in #315. So far, there are 2 votes to separate it out.

@stefanv
Copy link
Member

stefanv commented Mar 3, 2026

OK, but your vote is one of them, so perhaps you can explain why you think that's a good idea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Add an output parameter for coverage

2 participants