diff --git a/.github/workflows/tests-pytest.yml b/.github/workflows/tests-pytest.yml index 0817edf99..531c318c3 100644 --- a/.github/workflows/tests-pytest.yml +++ b/.github/workflows/tests-pytest.yml @@ -5,6 +5,14 @@ on: [push, pull_request] jobs: pytest: runs-on: ubuntu-latest + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for pushing data to the + # python-coverage-comment-action branch, and for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write steps: - name: Check out code uses: actions/checkout@v4 @@ -34,3 +42,10 @@ jobs: with: name: coverage-report path: benefits/static/coverage + + - name: Coverage comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ github.token }} + MINIMUM_GREEN: 90 + MINIMUM_ORANGE: 80 diff --git a/pyproject.toml b/pyproject.toml index 780a8a3c4..9b3f17975 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,8 +24,8 @@ dev = [ "pre-commit", ] test = [ + "coverage", "pytest", - "pytest-cov", "pytest-django", "pytest-mock", "pytest-socket", @@ -46,9 +46,12 @@ target-version = ['py311'] include = '\.pyi?$' [tool.coverage.run] +branch = true +relative_files = true omit = [ "benefits/core/migrations/*" ] +source = ["benefits"] [tool.djlint] ignore = "H017,H031" diff --git a/tests/pytest/core/test_models.py b/tests/pytest/core/test_models.py index 1ba7f2854..eb345920b 100644 --- a/tests/pytest/core/test_models.py +++ b/tests/pytest/core/test_models.py @@ -121,7 +121,7 @@ def test_EligibilityVerifier_str(model_EligibilityVerifier): assert str(model_EligibilityVerifier) == model_EligibilityVerifier.name -class TestFormClass: +class SampleFormClass: """A class for testing EligibilityVerifier form references.""" def __init__(self, *args, **kwargs): @@ -131,14 +131,14 @@ def __init__(self, *args, **kwargs): @pytest.mark.django_db def test_EligibilityVerifier_form_instance(model_EligibilityVerifier): - model_EligibilityVerifier.form_class = f"{__name__}.TestFormClass" + model_EligibilityVerifier.form_class = f"{__name__}.SampleFormClass" model_EligibilityVerifier.save() args = (1, "2") kwargs = {"one": 1, "two": "2"} form_instance = model_EligibilityVerifier.form_instance(*args, **kwargs) - assert isinstance(form_instance, TestFormClass) + assert isinstance(form_instance, SampleFormClass) assert form_instance.args == args assert form_instance.kwargs == kwargs diff --git a/tests/pytest/eligibility/test_views.py b/tests/pytest/eligibility/test_views.py index f7c6e3df5..3a8a430e1 100644 --- a/tests/pytest/eligibility/test_views.py +++ b/tests/pytest/eligibility/test_views.py @@ -53,7 +53,7 @@ def invalid_form_data(): return {"invalid": "data"} -class TestVerificationForm(EligibilityVerificationForm): +class SampleVerificationForm(EligibilityVerificationForm): def __init__(self, *args, **kwargs): super().__init__( "title", @@ -72,7 +72,7 @@ def __init__(self, *args, **kwargs): @pytest.fixture def model_EligibilityVerifier_with_form_class(mocker, model_EligibilityVerifier): - model_EligibilityVerifier.form_class = f"{__name__}.TestVerificationForm" + model_EligibilityVerifier.form_class = f"{__name__}.SampleVerificationForm" model_EligibilityVerifier.save() mocker.patch("benefits.eligibility.views.session.verifier", return_value=model_EligibilityVerifier) return model_EligibilityVerifier diff --git a/tests/pytest/run.sh b/tests/pytest/run.sh index afc4c5aff..37b044199 100755 --- a/tests/pytest/run.sh +++ b/tests/pytest/run.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash set -eu -pytest --cov=benefits --cov-branch --import-mode=importlib --no-migrations +# run normal pytests +coverage run -m pytest --no-migrations # clean out old coverage results rm -rf benefits/static/coverage + coverage html --directory benefits/static/coverage