#!/bin/sh
set -x

SRCDIR=$(pwd)
touch "$HOME/.bashrc" || exit $?

# Start the cluster, run the tests, capture test return code
PYTHONPATH="${SRCDIR}/metakernel_python/" ipcluster start -n=3 --daemonize || exit $?
python3 -m pytest --basetemp=${AUTOPKGTEST_TMP} /usr/lib/python3/dist-packages/metakernel
TESTRC=$?
# Always stop the cluster (even if tests fail)
ipcluster stop
STOPRC=$?
# If the test failed, exit with that return code, otherwise use the
# return code from stopping the cluster
if [ 0 -ne $TESTRC ]; then exit $TESTRC; else exit $STOPRC; fi
