[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!
This commit is contained in:
Cosimo Lupo 2016-02-06 21:53:01 +00:00
parent 118045abf0
commit 41dff8456e

View File

@ -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