Skip to content
Snippets Groups Projects
Commit 91a25396 authored by Saurabh Kumar's avatar Saurabh Kumar Committed by Fredrik Jonsson
Browse files

Improve testing and development experience

- Add “make test” command to lint, test and report coverage
- Add pytest runner 
  - It automatically set up to use the correct Django settings module
  - Runs tests on all the available CPU, I was able to run all the test in total=~30sec using “make test” command.
  - It provides a cleaner error report, compared to DjangoTestRunner
- Coverage
  - Displayed the report on the terminal after the test finish
  - Disable reporting of coverage for test and migration files
  - Enable coverage reporting for the template files
  - “make test” generates HTML reports to quickly check the coverage of each file
parent 7374b8d4
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,7 @@ jobs: ...@@ -96,7 +96,7 @@ jobs:
command: | command: |
python3 -m venv venv python3 -m venv venv
. venv/bin/activate . venv/bin/activate
pip install coverage codecov pip install codecov
pip install -r requirements-dev.txt pip install -r requirements-dev.txt
- save_cache: - save_cache:
paths: paths:
...@@ -118,8 +118,7 @@ jobs: ...@@ -118,8 +118,7 @@ jobs:
name: run linting name: run linting
command: | command: |
. venv/bin/activate . venv/bin/activate
flake8 ./hypha make lint
make sort
test-be: test-be:
executor: with-database executor: with-database
...@@ -135,7 +134,7 @@ jobs: ...@@ -135,7 +134,7 @@ jobs:
python manage.py check python manage.py check
python manage.py makemigrations --check --noinput --verbosity=1 python manage.py makemigrations --check --noinput --verbosity=1
python manage.py collectstatic --noinput --no-post-process --verbosity=1 python manage.py collectstatic --noinput --no-post-process --verbosity=1
coverage run --source='hypha' manage.py test pytest --cov
codecov codecov
......
...@@ -32,10 +32,12 @@ wheels/ ...@@ -32,10 +32,12 @@ wheels/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
.coverage
htmlcov/
# Cache # Cache
.mypy_cache/ .mypy_cache/
.pytest_cache/
# Webpack # Webpack
webpack-stats.json webpack-stats.json
......
.nvmrc 0 → 100644
v16.14.2
...@@ -3,6 +3,7 @@ help: ...@@ -3,6 +3,7 @@ help:
@echo "Usage:" @echo "Usage:"
@echo " make help prints this help." @echo " make help prints this help."
@echo " make lint run all python linting." @echo " make lint run all python linting."
@echo " make test run all python linting and test"
@echo " make sort run the isort import linter." @echo " make sort run the isort import linter."
@echo " make sort-fix fix import sort order." @echo " make sort-fix fix import sort order."
@echo " make style run the python code style linter." @echo " make style run the python code style linter."
...@@ -12,12 +13,17 @@ lint: sort style ...@@ -12,12 +13,17 @@ lint: sort style
.PHONY: sort .PHONY: sort
sort: sort:
@echo "Checking imports with isort" && isort --check-only --diff . @echo "Checking imports with isort" && isort --check-only --diff hypha
.PHONY: sort-fix .PHONY: sort-fix
sort-fix: sort-fix:
@echo "Fixing imports with isort" && isort . @echo "Fixing imports with isort" && isort hypha
.PHONY: style .PHONY: style
style: style:
@echo "Checking code style with flake8" && flake8 . @echo "Checking code style with flake8" && flake8 .
test: lint
pytest --reuse-db --cov --cov-report term:skip-covered
@rm -rf htmlcov
coverage html
...@@ -24,3 +24,6 @@ PASSWORD_HASHERS = [ ...@@ -24,3 +24,6 @@ PASSWORD_HASHERS = [
] ]
WAGTAILADMIN_BASE_URL = "https://primary-test-host.org" WAGTAILADMIN_BASE_URL = "https://primary-test-host.org"
# Required by django-coverage-plugin to report template coverage
TEMPLATES[0]['OPTIONS']['debug'] = True
-r requirements.txt -r requirements.txt
django-debug-toolbar==3.2.2 django-debug-toolbar==3.6.0
factory_boy==3.2.1 factory_boy==3.2.1
flake8==5.0.1 flake8==5.0.4
isort==5.10.1 isort==5.10.1
model-bakery==1.3.3 model-bakery==1.7.0
responses==0.16.0 responses==0.21.0
stellar==0.4.5 stellar==0.4.5
wagtail-factories==2.1.0 wagtail-factories==2.1.0
Werkzeug==2.0.2 Werkzeug==2.2.2
pytest-django==4.5.2
pytest-xdist[psutil]==2.5.0
coverage==6.4.4
pytest-cov==3.0.0
django-coverage-plugin==2.0.3
[flake8] [flake8]
ignore = E501,W503,F405,F821,W504,W605 ignore = E501,W503,F405,F821,W504,W605
exclude = migrations,node_modules,venv
max-line-length = 88 max-line-length = 88
exclude =
.*/,
__pycache__/,
*migrations/,
node_modules/,
venv/,
media/,
static/,
htmlcov/
[isort] [isort]
force_grid_wrap = 0 force_grid_wrap = 0
...@@ -10,3 +18,19 @@ line_length = 88 ...@@ -10,3 +18,19 @@ line_length = 88
multi_line_output = 3 multi_line_output = 3
skip_glob = .direnv,node_modules,venv,**/migrations/** skip_glob = .direnv,node_modules,venv,**/migrations/**
use_parentheses = True use_parentheses = True
[tool:pytest]
DJANGO_SETTINGS_MODULE = hypha.settings.test
addopts = -n auto --failed-first
python_files = tests.py test_*.py *_tests.py
testpaths =
hypha
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
[coverage:run]
plugins = django_coverage_plugin
omit =
*migrations*,
*test*
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment