forked from quantumlib/Cirq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytest
executable file
·51 lines (44 loc) · 1.47 KB
/
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
#!/usr/bin/env bash
################################################################################
# Runs pytest on the repository.
#
# Usage:
# check/pytest [--actually-quiet] [--flags for pytest] [file-paths-relative-to-repo-root]
#
# The --actually-quiet argument filters out any progress output from pytest.
#
# You may specify pytest flags and specific files to test. The file paths
# must be relative to the repository root. If no files are specified, everything
# is tested.
################################################################################
# Get the working directory to the repo root.
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$(git rev-parse --show-toplevel)"
PYTEST_ARGS=()
ACTUALLY_QUIET=""
for arg in $@; do
if [[ "${arg}" == "--actually-quiet" ]]; then
ACTUALLY_QUIET=1
else
PYTEST_ARGS+=("${arg}")
fi
done
source dev_tools/pypath
PYTHON_VERSION=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
if [ "$PYTHON_VERSION" -lt "37" ]; then
PYTEST_ARGS+=("--ignore=cirq-rigetti")
fi
if [ -z "${ACTUALLY_QUIET}" ]; then
pytest "${PYTEST_ARGS[@]}"
RESULT=$?
else
# Filter out lines like "...F....x... [ 42%]", with coloring.
pytest -q --color=yes "${PYTEST_ARGS[@]}" |
perl -nle'print if not m{^(.\[0m)?[\.FEsx]+(.\[36m)?\s+\[\s*\d+%\](.\[0m)?$}'
RESULT=${PIPESTATUS[0]}
fi
if [ "$RESULT" = 5 ]; then
echo "[exit 5] No tests collected, but ignored."
exit 0
fi
exit "$RESULT"