Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add coverage comments to PRs #1745

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/tests-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dev = [
"pre-commit",
]
test = [
"coverage",
"pytest",
"pytest-cov",
"pytest-django",
"pytest-mock",
"pytest-socket",
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/pytest/eligibility/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/pytest/run.sh
Original file line number Diff line number Diff line change
@@ -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
Loading