Last active
April 6, 2017 03:48
-
-
Save aljp/a6fa55f0708f290505e2b7efe7dba153 to your computer and use it in GitHub Desktop.
Run's tests and generates coverage reports for a Django Project, then opens the coverage reports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Adam Jacquier-Parr | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
NC='\033[0m' | |
# Check script is being run with source | |
if [ "$0" = "$BASH_SOURCE" ]; then | |
echo -e "${RED}You must use 'source test.sh' to run this script.${NC}" | |
exit 1 | |
fi | |
# Check virtualenv is active, may be overkill? | |
if [[ "$VIRTUAL_ENV" == "" ]] | |
then | |
echo -e "${RED}You must activate the virtual environment.${NC}" | |
return 1 | |
fi | |
# Run tests | |
coverage run manage.py test "$@" | |
if [ $? -ne 0 ]; then | |
echo -e "${RED}Tests have failed, coverage reports will be skipped.${NC}" | |
return 1 | |
else | |
echo -e "${GREEN}Tests have complete! Coverage reports are comming up!${NC}" | |
fi | |
# Generate HTML Coverage Report | |
coverage html --include=./*/*.py --omit=./*/migrations/*.py,./*/tests/*,./venv/* | |
echo -e "${GREEN}The coverage report has been completed!${NC}" | |
open ./htmlcov/index.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment