Created
March 20, 2014 09:04
-
-
Save jlnwlf/9659899 to your computer and use it in GitHub Desktop.
git pre-commit hook for Python Unittest + autopep8 check
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 | |
autopep=$(autopep8 -dr .) | |
if [[ -z $autopep ]] | |
then | |
echo "> PEP8 passed !" | |
else | |
echo "> PEP8 DID NOT pass !" | |
echo "$autopep" | colordiff | |
exit 1 | |
fi | |
if [[ `python -m unittest discover .` ]] | |
then | |
echo "> Tests DID NOT pass !" | |
exit 1 | |
else | |
echo "> Tests passed !" | |
fi | |
echo "Ready to commit !" | |
exit 0 |
That seems wrong... You're checking the output of the discover command instead of its exit code. Here is my version:
#!/bin/sh
`python -m unittest discover -p "*_test.py"`
if [[ $? = 0 ]]
then
echo "> Tests passed"
else
echo "> Tests DID NOT pass"
exit 1
fi
echo "Ready to commit"
exit 0
@vitalybe
Thanks for the correction. This works !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for the snippet! Just one thing.
Don't you think the if clause is in the wrong order? Shouldn't it be:
Otherwise it would be failing when successful