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 |
Hi, thanks for the snippet! Just one thing.
Don't you think the if clause is in the wrong order? Shouldn't it be:
then
echo "> Tests passed !"
else
echo "> Tests DID NOT pass !"
exit 1
fi
Otherwise it would be failing when successful
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
Heyo,
just found this and tried it out. Unfortunately under Ubuntu 15.10 this doesn't work correctly, in that it always passes.
The output of the commands is seemingly completely ignored.
Unfortunately, my BASH-fu is not good enough to provide a fix (yet), so I thought I'd let you know.
Cheers!