Skip to content

Commit

Permalink
Add additional runners arg to pytest.coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Mar 18, 2022
1 parent 3b79f06 commit bf52a60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Changelog
=========

- :feature:`-` Allow supplying additional test runners to ``pytest.coverage``;
primarily useful for setting up multiple additive test runs before publishing
reports.
- :feature:`-` Add a new `invocations.ci` task module for somewhat-more-generic
CI support than the now legacy `invocations.travis` tasks.
- :feature:`-` Add additional CLI flags to the use of ``gpg`` when signing
Expand Down
17 changes: 15 additions & 2 deletions invocations/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def integration(
)


@task
def coverage(c, report="term", opts="", tester=None, codecov=False):
@task(iterable=['additional_testers'])
def coverage(c, report="term", opts="", tester=None, codecov=False, additional_testers=None):
"""
Run pytest with coverage enabled.
Expand All @@ -138,12 +138,25 @@ def coverage(c, report="term", opts="", tester=None, codecov=False):
:param bool codecov:
Whether to build XML and upload to Codecov. Requires ``codecov`` tool.
Default: ``False``.
:param additional_testers:
List of additional test functions to call besides ``tester``. If given,
implies the use of ``--cov-append`` on these subsequent test runs.
.. versionchanged:: 2.4
Added the ``additional_testers`` argument.
"""
my_opts = "--cov --no-cov-on-fail --cov-report={}".format(report)
if opts:
my_opts += " " + opts
# TODO: call attached suite's test(), not the one in here, if they differ
# TODO: arguably wants ability to lookup task string when tester(s) given
# on CLI, but, eh
(tester or test)(c, opts=my_opts)
if additional_testers:
my_opts += " --cov-append"
for tester in additional_testers:
tester(c, opts=my_opts)
if report == "html":
c.run("open htmlcov/index.html")
if codecov:
Expand Down

0 comments on commit bf52a60

Please sign in to comment.