From 41dff8456e2e1db195dcc4dc95ece97c56faf1a9 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sat, 6 Feb 2016 21:53:01 +0000 Subject: [PATCH] [run-test.sh] use pytest to collect tests This way test discovery will work not only with the current unittest and doctest modules, but also with pytest's own kind of tests. When run with no argument, the shell script will call the py.test command, which will scan the whole Lib/fontTools directory for all relevant tests. If args are provided, tests are filtered if any of the substrings specified match. The filtering works not only on the modules' file names (as the previous grep approach), but also on the names of the test functions, classes and methods. Pretty cool, huh? We can still specify whether to run pytest with python -2 or -3 (provided pytest is installed on both Python versions). And we don't need to print the python version any more as pytest does it for us. Finally, there's no need to export PYTHONPATH -- pytest takes care of that too! --- run-tests.sh | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index e97e9c3f5..662d19aef 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -12,46 +12,17 @@ elif test "x$1" = x-2; then shift fi test "x$PYTHON" = x && PYTHON=python -echo "$(which $PYTHON) --version" -$PYTHON --version 2>&1 -echo - -# Setup environment -DIR=`dirname "$0"` -cd "$DIR/Lib" -if [ "x$PYTHONPATH" != "x" ]; then - PYTHONPATH=".:$PYTHONPATH" -else - PYTHONPATH="." -fi -export PYTHONPATH # Find tests -FILTER= +FILTERS= for arg in "$@"; do - test "x$FILTER" != x && FILTER="$FILTER|" - FILTER="$FILTER$arg" + test "x$FILTERS" != x && FILTERS="$FILTERS or " + FILTERS="$FILTERS$arg" done -test "x$FILTER" = "x" && FILTER=. -TESTS=`grep -r --include='*.py' -l -e doctest -e unittest * | grep -E "$FILTER"` - -ret=0 -FAILS= -for test in $TESTS; do - echo "Running tests in $test" - test=`echo "$test" | sed 's@[/\\]@.@g;s@[.]py$@@'` - if ! $PYTHON -m $test -v; then - ret=$((ret+1)) - FAILS="$FAILS -$test" - fi -done - echo - echo "SUMMARY:" -if test $ret = 0; then - echo "All tests passed." +# Run tests +if [ -z "$FILTERS" ]; then + $PYTHON -m pytest else - echo "$ret source file(s) had tests failing:$FAILS" >&2 + $PYTHON -m pytest -k "$FILTERS" fi -exit $ret