# HG changeset patch # User Andrey Skvortsov # Date 1538736534 -10800 # Node ID 82bfc75bcd9dc224abf9b147e1bd569f69dd54c8 # Parent 925adaa2cd5c56a42682da96a50c630da9baa6f3 Make easier to run pytest on local X-server diff -r 925adaa2cd5c -r 82bfc75bcd9d tests/tools/run_python_tests.sh --- a/tests/tools/run_python_tests.sh Fri Oct 05 13:11:28 2018 +0300 +++ b/tests/tools/run_python_tests.sh Fri Oct 05 13:48:54 2018 +0300 @@ -1,28 +1,61 @@ #!/bin/sh + + cleanup() { - find ./tests/tools -name '*.pyc' -delete + find $PYTEST_DIR -name '*.pyc' -delete } -LC_ALL=ru_RU.utf-8 - -export DISPLAY=:42 -Xvfb $DISPLAY -screen 0 1280x1024x24 & -sleep 1 -cleanup +print_help() +{ + echo "Usage: run_python_tests.sh [--on-local-xserver]" + echo "" + echo "--on-local-xserver" + echo " all tests are run on local X-server. " + echo " User can see test in action." + echo " Any interaction (mouse, keyboard) should be avoided" + echo " By default without arguments script runs pytest on virtual X serverf." + echo "" -ret=0 -DELAY=400 -KILL_DELAY=$(($DELAY + 30)) -timeout -k $KILL_DELAY $DELAY pytest --timeout=10 ./tests/tools -ret=$? + exit 1 +} -cleanup +main() +{ + LC_ALL=ru_RU.utf-8 + PYTEST_DIR=./tests/tools + + if [ ! -d $PYTEST_DIR ]; then + echo "Script should be run from top directory in repository" + exit 1; + fi + + use_xvfb=0 + if [ "$1" != "--on-local-xserver" ]; then + export DISPLAY=:42 + use_xvfb=1 + Xvfb $DISPLAY -screen 0 1280x1024x24 & + sleep 1 + fi -pkill -9 Xvfb + cleanup -exit $ret + ret=0 + DELAY=400 + KILL_DELAY=$(($DELAY + 30)) + timeout -k $KILL_DELAY $DELAY pytest --timeout=10 ./tests/tools + ret=$? + + cleanup + + [ $use_xvfb = 1 ] && pkill -9 Xvfb + exit $ret +} + + +[ "$1" = "--help" -o "$1" = "-h" ] && print_help +main $@