FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programmingWithPythonCode/_scripts_/pytest.sh at main · thomasWeise/programmingWithPythonCode · GitHub
thomasWeise
programmingWithPythonCode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programmingWithPythonCode
/
_scripts_
/
pytest.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
53 lines (46 loc) · 2.2 KB
Breadcrumbs
programmingWithPythonCode
/
_scripts_
/
pytest.sh
Copy path
File metadata and controls
executable file
·
53 lines (46 loc) · 2.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/bin/bash -
#
This is our internal pytest execution script.
#
It prints the pytest command and the results of pytest.
#
It always exits with an exit code 0, even if pytest fails.
#
Argument $1: the folder to run it in
#
Argument $2: the file(s) to scan
#
We enforce strict error handling, i.e., fail on any unexpected error.
set
-o pipefail
#
trace errors through pipes
set
-o errtrace
#
trace errors through commands and functions
set
-o nounset
#
exit if encountering an uninitialized variable
set
-o errexit
#
exit if any statement returns a non-0 return value
#
Check if pytest and all required plugins are installed.
versions=
"
"
#
This variable will receive all tool versions.
for
pack
in
"
pytest
"
"
pytest-timeout
"
;
do
infos=
"
$(
python3 -m pip show
"
$pack
"
2>
/dev/null
||
true
)
"
if
[
-z
"
$infos
"
]
;
then
#
pytest or the plugin is not installed, so we install it now.
#
We do this silently, without printing any information...
python3 -m pip install --require-virtualenv
"
$pack
"
1>
/dev/null
2>&1
infos=
"
$(
python3 -m pip show
"
$pack
"
2>
/dev/null
)
"
fi
#
For each tool or plugin, we get the version separately.
infos=
"
$(
grep Version:
<<<
"
$infos
"
)
"
infos=
"
$(
sed -n
'
s/.*Version:\s*\([.0-9]*\)/\1/p
'
<<<
"
$infos
"
)
"
if
[
-z
"
$versions
"
]
;
then
#
... and we concatenate them
versions=
"
$pack
$infos
with
"
elif
[[
"
$versions
"
==
*
with ]]
;
then
versions=
"
$versions
$pack
$infos
"
else
versions=
"
$versions
,
$pack
$infos
"
fi
done
#
Construct the pytest command.
command=
"
pytest --timeout=10 --no-header --tb=short
$2
"
echo
"
\$
$command
"
#
We print the command line which will be executed.
cd
"
$1
"
#
We enter the folder inside of which we should execute pytest.
export
COLUMNS=73
#
Switch of "exit-on-error", run pytest, and afterwards switch it back on.
set
+o errexit
#
Turn off exit-on-error.
$command
2>&1
|
sed
'
/^[[:space:]]*$/d
'
#
Run pytest, clean output.
exitCode=
"
$?
"
#
Store exit code of program in variable exitCode.
set
-o errexit
#
Turn exit-on-error back on.
#
Convert exit code to success or failure string.
[
"
$exitCode
"
-eq
0 ]
&&
exitCodeStr=
"
succeeded
"
||
exitCodeStr=
"
failed
"
#
Finally, we print the result string.
echo
"
#
$versions
$exitCodeStr
with exit code
$exitCode
.
"
Back
|
FazBrowse Home
|
New Git URL