-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·73 lines (62 loc) · 1.47 KB
/
test.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env bash
# Run pytests and doctests (by unittest) locally
#
# do not forget `. ./activate.sh` before running this script,
# add `127.0.0.1 postgres` into ` /etc/hosts`
# run `docker-compose up -d postgres`
#
# passes params to pytest.
# returned exit code are cumulative of pytest and doctests
#
# Example:
# ./test.sh -k enumerate
set -o allexport
source env/dev-backend.env
source env/dev-celeryworker.env
set +o allexport
# run tests with DB settings from .env
POSTGRES_CREDENTIALS="env/dev-postgres.env"
export $(grep -v '^#' ${POSTGRES_CREDENTIALS} | xargs)
RED='\033[1;31m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NC='\033[0m' # No Color
NL=$'\n'
RUN_DOCTESTS=1
PYTEST_ARGS=""
if [[ "$@" != *"-k"* && "$@" != *"-m"* ]]; then
PYTEST_ARGS="-n 4"
fi
PY_IGNORE_IMPORTMISMATCH=1 PYTHONPATH=backend \
python -m pytest \
--instafail \
--picked=first \
--cov-report=term-missing:skip-covered \
--cov=backend/app \
-s -vv \
backend/tests/ \
$PYTEST_ARGS \
"$@"
if [ $? -eq 0 ]; then
echo
echo -e $GREEN".. pytest success .."$NC
EXIT_CODE=0
else
echo
echo -e $RED".. pytest FAIL!"$NC
EXIT_CODE=1
fi
if [[ $RUN_DOCTESTS == 1 ]]; then
PYTHONPATH=backend python -m unittest --verbose tests.test_doctests
if [ $? -eq 0 ]; then
echo
echo -e $GREEN".. doctests success .."$NC
EXIT_CODE=$((0 || $EXIT_CODE))
else
echo
echo -e $RED"doctests FAIL!"$NC
EXIT_CODE=1
fi
echo
fi
exit $EXIT_CODE