Skip to content

Commit

Permalink
add code coverage checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jfredrickson committed Apr 14, 2023
1 parent 6a281e8 commit 3a4ba4a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/backend-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Backend API tests and code coverage

on:
- push

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- "3.10"

services:
postgres:
image: postgres:12 # For best results, match version in use by cloud.gov RDS
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install pip
run: python -m pip install --upgrade pip

- name: Install prerequisites
run: pip install -r requirements.txt -r requirements.dev.txt

- name: Run unit tests with test coverage checking
run: coverage run -m pytest

- name: Verify >= 90% test coverage
run: coverage report --fail-under=90
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
.pytest_cache
_site/
node_modules
.coverage
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ npm run dev

## Testing

To run tests, first ensure that the `DB_URI` environment variable is set to an empty test database (example: `postgres://postgres:postgres@localhost:5432/smartpay-test`), then run:
To run tests with code coverage checking:

```
pytest
coverage run -m pytest
```

To view the coverage report afterwards:

```
coverage report
```

## Deployment
Expand Down
3 changes: 2 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
flake8==6.0.0
pytest==7.2.1
httpx==0.23.3
httpx==0.23.3
coverage==7.2.3

0 comments on commit 3a4ba4a

Please sign in to comment.