Skip to content

Use pytest #49

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

Merged
merged 8 commits into from
Jun 14, 2021
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
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[report]
show_missing = True
omit =
manage.py
venv/*
*wsgi.py
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
.DEFAULT_GOAL := help

help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


.PHONY: build_frontend run_frontend run_django run install_dependencies setup_node_environment

build_frontend:
build_frontend: ## build frontend application
npm run build

run_frontend:
run_frontend: ## run frontend application
npm start

run_django:
run_django: ## run backend application
python manage.py runserver

run:
run: ## run both backend and frontend applications
make -j2 run_django run_frontend

install_dependencies:
install_dependencies: ## install both backend and frontend dependencies
make setup_node_environment
pip install -r requirements.txt
npm i

setup_node_environment:
setup_node_environment: ## setup node environment
curl -o- https://github.com/raw/nvm-sh/nvm/v0.35.3/install.sh | bash
export NVM_DIR=$$HOME/.nvm; . ~/.nvm/nvm.sh ; nvm install

test: ## run the tests
pytest

cov: ## run the tests, and open coverage report in your favorite browser
pytest && python -m webbrowser -t htmlcov/index.html
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ make run

Since nvm can be a little fiddly, if you have any issues with it, [try reading their documentation](https://github.com/nvm-sh/nvm#installing-and-updating) on how to use it.

## Testing it

Run the command `pytest` in the main directory, or run the script `make test`.

For coverage report, run the script `make cov`. Your default browser will open with the report for the tests, if all tests pass.

## Adding new dependencies

If you wish to add new dependencies, just note that:
Expand Down
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
DJANGO_SETTINGS_MODULE = project.settings

python_files = test.py test_*.py *_tests.py

addopts = --cov-report html --cov .
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ asgiref==3.2.5
attrs==19.3.0
black==19.10b0
click==7.1.1
coverage==5.5
dj-database-url==0.5.0
Django==3.0.4
django-heroku==0.3.1
Expand All @@ -12,15 +13,25 @@ djangorestframework==3.11.0
entrypoints==0.3
flake8==3.7.9
gunicorn==20.0.4
iniconfig==1.1.1
mccabe==0.6.1
packaging==20.9
pathspec==0.7.0
pluggy==0.13.1
psycopg2==2.8.4
py==1.10.0
pycodestyle==2.5.0
pyflakes==2.1.1
pyparsing==2.4.7
pytest==6.2.4
pytest-cov==2.12.1
pytest-django==4.4.0
pytest-sugar==0.9.4
python-decouple==3.3
pytz==2019.3
regex==2020.2.20
sqlparse==0.3.1
termcolor==1.1.0
toml==0.10.0
typed-ast==1.4.1
whitenoise==5.0.1
Empty file added tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_sample():
assert True