Skip to content

Commit

Permalink
Implementation of code coverage and unit test workflow (#453)
Browse files Browse the repository at this point in the history
* Implementation of code coverage and unit test workflow

* Minor change

* Minor change

* Some changes

* experiment

* Experiment

* Update unit-test-and-code-coverage.yml

* Update unit-test-and-code-coverage.yml

* Minor change

* Minor change

* minor changes

* Minor testing

* Minor changes for experiment

* Minor changes

* Testing changes

* Testing more changes

* reverting previous changes

* Update unit-test-and-code-coverage.yml

* debugging changes

* debugging issues

* Minor changes

* Running migration commands directly

* Reverting back the existing changes

* Update unit-test-and-code-coverage.yml

* Update unit-test-and-code-coverage.yml

* Update unit-test-and-code-coverage.yml

* Update unit-test-and-code-coverage.yml

* Update conftest.py

* Update unit-test-and-code-coverage.yml

* Update unit-test-and-code-coverage.yml

* Minor change

* Update unit-test-and-code-coverage.yml
  • Loading branch information
thebelrobot authored Dec 14, 2023
1 parent 4ae0ece commit 7b66a89
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/unit-test-and-code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Run Tests and Generate Code Coverage

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

env:
FLASK_APP: "/home/runner/work/RP_IVR_ANALYTICS/RP_IVR_ANALYTICS/manage.py"
TEST_DB_USER: "postgres"
TEST_DB_PASSWORD: "postgres"
TEST_DB_DATABASE: "dost_test"
TEST_DB_HOST: 127.0.0.1
TEST_DB_POST: 5432
admin_server: 127.0.0.1
FLASK_ENV: "testing"
TESTING: True
DEBUG: True
SECRET_KEY: ""
RETRY_LOGS_BATCH_LIMIT: 1000
MAX_RETRY_ATTEMPTS_FOR_LOGS: 3%
SQLALCHEMY_DATABASE_URI_GITHUB_ACTION: "postgresql://postgres:[email protected]:5432/dost_test"

jobs:
test:
name: Run tests & display coverage
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
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dost_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Install PostgreSQL client
run: |
sudo apt-get update
sudo apt-get install --yes postgresql-client
- uses: actions/checkout@v3
- name: Install Python 3
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Copy .env
run: cp .env.example .env
- name: Install dependencies
run: pip install -r requirements.txt
- name: Upgrade db
run: python -m flask db upgrade
- name: Launch tests & generate report
run: python -m pytest --junitxml=pytest.xml --cov > pytest-coverage.txt
- name: Print Coverage report
run: cat pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
hide-report: true
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Flask-Script==2.0.6
pytest==7.4.3
faker==20.1.0
setuptools==68.2.2
pytest-cov==4.0.0
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ def setup_test_environment(db):
os.system("flask db upgrade")

# Loading pre-filled data for running tests.
try:
testing_seeder.main()
except:
db.session.rollback()
testing_seeder.main()
2 changes: 1 addition & 1 deletion tests/test_call_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_update_call_log(app, db, setup_test_environment):
new_content_id = None
new_language_id = None
while not stop_iteration:
random_index = randint(0, len(all_content_version_records))
random_index = randint(0, len(all_content_version_records) - 1)
if (
all_content_version_records[random_index].id
!= pytest.initial_content_version_id
Expand Down

1 comment on commit 7b66a89

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Tests Skipped Failures Errors Time
3 0 💤 0 ❌ 0 🔥 1.907s ⏱️

Please sign in to comment.