diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba5ced3..15a114c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,4 +24,6 @@ jobs: pip install tox - name: Run tests - run: tox + env: + GITHUB_TOKEN: ${{ github.token }} + run: tox -e cov-ci diff --git a/.gitignore b/.gitignore index 3a31716..bec026d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/__pycache__/ dist/ .tox/ +.coverage diff --git a/tests/test_plugin.py b/tests/test_plugin.py new file mode 100644 index 0000000..87a839e --- /dev/null +++ b/tests/test_plugin.py @@ -0,0 +1,46 @@ +# High-level test of the entire plugin. +from unittest import mock +import argparse + +from pluggy import PluginManager + +import pytest_filecov.plugin + + +class FakePluginManager: + def __init__(self): + self.registered = None + + def register(self, plugin): + assert not self.registered + self.registered = plugin + + +class FakeConfig: + def __init__(self, filecov): + self.filecov = filecov + + @property + def option(self): + return self + + +def test_plugin_noop(): + parser = mock.Mock(spec=["getgroup", "addoption"]) + pm = FakePluginManager() + pytest_filecov.plugin.pytest_addoption(parser, pm) + + # Should have registered + assert pm.registered + + # Do a test in the case where no monitoring is requested + config = FakeConfig([]) + + plugin = pm.registered + + # These should all work and do effectively nothing + plugin.pytest_configure(config) + plugin.pytest_sessionstart(object()) + plugin.pytest_sessionfinish(object()) + assert plugin.pytest_report_header(object(), object()) == [] + plugin.pytest_terminal_summary(object()) diff --git a/tox.ini b/tox.ini index 5a3c326..2b17ed6 100644 --- a/tox.ini +++ b/tox.ini @@ -2,4 +2,19 @@ envlist = py38 [testenv] -commands=pytest -v {posargs} +usedevelop=true +deps= + pytest-cov +commands= + pytest -v --cov=pytest_filecov {posargs} + +[testenv:cov-ci] +passenv=GITHUB_* +usedevelop=true +deps= + pytest-cov + coveralls +commands= + pytest -v --cov=pytest_filecov {posargs} + coveralls --service=github +