aurweb/docker/scripts/run-pytests.sh
Kevin Morris 7b7e571e93
change(FastAPI): run test_initdb.py ahead of time in docker
In some cases, when tests fail through Docker, the database
ends up in an invalid state. This causes subsequent runs to
error out with non-sensical DB errors. The `test_initdb.py`
test suite runs tests which setup every modifiable table
in the database, so let's just run it first here to avoid
any invalid test DB state.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-10-15 20:16:38 -07:00

47 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
set -eou pipefail
COVERAGE=1
PARAMS=()
while [ $# -ne 0 ]; do
key="$1"
case "$key" in
--no-coverage)
COVERAGE=0
shift
;;
-*)
echo "usage: $0 [--no-coverage] targets ..."
exit 1
;;
*)
PARAMS+=("$key")
shift
;;
esac
done
# Initialize the new database; ignore errors.
python -m aurweb.initdb 2>/dev/null || \
(echo "Error: aurweb.initdb failed; already initialized?" && /bin/true)
# Run test_initdb ahead of time, which clears out the database,
# in case of previous failures which stopped the test suite before
# finishing the ends of some test fixtures.
eatmydata -- pytest test/test_initdb.py
# Run pytest with optional targets in front of it.
eatmydata -- make -C test "${PARAMS[@]}" pytest
# By default, report coverage and move it into cache.
if [ $COVERAGE -eq 1 ]; then
make -C test coverage
# /cache is mounted as a volume. Copy coverage into it.
# Users can then sanitize the coverage locally in their
# aurweb root directory: ./util/fix-coverage ./cache/.coverage
rm -f /cache/.coverage
cp -v .coverage /cache/.coverage
chmod 666 /cache/.coverage
fi