-
Notifications
You must be signed in to change notification settings - Fork 22
/
run-pytest
executable file
·60 lines (50 loc) · 1.5 KB
/
run-pytest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Run pytest locally or on docker-compose app service
#
# When using docker-compose app service, the options passed by VSCodium
# will be handled specially to make its pytest integration smoother.
#
# To run pytest within docker, set USE_DOCKER environment variable to 1
# or add USE_DOCKER=1 to the .env file.
set -e
USE_DOCKER=${USE_DOCKER}
if [[ -z "$USE_DOCKER" ]] && [[ -e .env ]]; then
USE_DOCKER=$(sed -n '/^USE_DOCKER=/s/^[^=]*=//p' .env)
fi
if [[ "$USE_DOCKER" == "1" ]] || [[ "$USE_DOCKER" == "yes" ]]; then
docker-compose up -d
else
exec pytest "$@"
exit $?
fi
unset xml_file
opts=()
while [[ $# -gt 0 ]]; do
opt="$1"
shift
if [[ "$opt" == "--rootdir" ]]; then # Ignore rootdir option
shift # Ignore also the argument to --rootdir
continue
elif [[ "$opt" == --junit-xml=* ]]; then # Parse junit-xml option
xml_file=${opt#--junit-xml=}
opt="--junit-xml=/tmp/pytest_junit.xml"
fi
opts+=("$opt")
done
misc_opts=(
"-o" "cache_dir=/tmp/pytest_cache"
)
docker_compose_exec=("docker-compose" "exec")
if ! tty -s; then
docker_compose_exec+=("-T") # If there is no TTY available, pass -T
fi
# Wait until the database is ready
"${docker_compose_exec[@]}" -e RUN_MIGRATIONS=0 app ./docker-entrypoint /bin/true
set +e
"${docker_compose_exec[@]}" app pytest "${misc_opts[@]}" "${opts[@]}"
exit_code=$?
set -e
if [[ -n "$xml_file" ]]; then
"${docker_compose_exec[@]}" app cat /tmp/pytest_junit.xml > "$xml_file"
fi
exit $exit_code