Skip to content

Commit faa60d7

Browse files
authored
Fix: st2-run-pack-tests (#6340)
* Fix: st2-run-pack-tests - Include dependency for pytest-cov to allow coverage to be included when running script with '-c' - Fix test path when specifying the file with '-f' - Correct '-f' usage to follow pytest syntax: test_action_download.py::DownloadGitRepoActionTestCase::test_run_pack_download
1 parent ea35b8c commit faa60d7

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Added
8080
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
8181
#6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307
8282
#6311 #6314 #6315 #6317 #6319 #6312 #6320 #6321 #6323 #6324 #6325 #6326 #6327 #6328
83-
#6329 #6330
83+
#6329 #6330 #6337
8484
Contributed by @cognifloyd
8585
* Build of ST2 EL9 packages #6153
8686
Contributed by @amanda11

st2common/bin/st2-run-pack-tests

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ function join { local IFS="$1"; shift; echo "$*"; }
3636
PACK_TEST_PYTHON_DEPENDENCIES_NAMES=(
3737
'pytest'
3838
'mock'
39-
'coverage'
39+
'pytest-cov'
4040
)
4141
PACK_TEST_PYTHON_DEPENDENCIES_VERSIONS=(
4242
'>7'
4343
'>=4.0.3'
44-
'>=4.4.1'
44+
'>=6.1.1'
4545
)
4646

4747
VIRTUALENVS_DIR="/tmp/st2-pack-tests-virtualenvs"
@@ -69,7 +69,7 @@ STACKSTORM_VIRTUALENV_PYTHON_BINARY="${STACKSTORM_VIRTUALENV_BIN}/python"
6969

7070
function usage() {
7171
echo "Usage: $0 [-c] [-j] [-t] [-v] [-x] -p <path to pack> [-f <test file module / class / method>]" >&2
72-
echo " -f : Run a specific test file or test class method (e.g. -f test_action_download:DownloadGitRepoActionTestCase.test_run_pack_download)" >&2
72+
echo " -f : Run a specific test file or test class method (e.g. -f test_action_download.py::DownloadGitRepoActionTestCase::test_run_pack_download)" >&2
7373
echo " -c : Run tests with code coverage reporting enabled" >&2
7474
echo " -j : Just run tests. Use previously installed dependencies" >&2
7575
echo " and virtualenv, if any, for subsequent test runs." >&2
@@ -270,7 +270,7 @@ elif [ "${ENABLE_COVERAGE}" = true ]; then
270270
for((i = 0; i < ${#PACK_TEST_PYTHON_DEPENDENCIES_NAMES[@]}; i++)); do
271271
DEPENDENCY_NAME="${PACK_TEST_PYTHON_DEPENDENCIES_NAMES[$i]}"
272272

273-
if [ "${DEPENDENCY_NAME}" = "coverage" ]; then
273+
if [ "${DEPENDENCY_NAME}" = "pytest-cov" ]; then
274274
DEPENDENCY_VERSION="${PACK_TEST_PYTHON_DEPENDENCIES_VERSIONS[$i]}"
275275

276276
echo ${INSTALLED_PIP_PACKAGES} | grep "${DEPENDENCY_NAME}" > /dev/null || pip install --cache-dir ${HOME}/.pip-cache ${ST2_PIP_OPTIONS} "${DEPENDENCY_NAME}${DEPENDENCY_VERSION}"
@@ -333,23 +333,15 @@ if [ "${ENABLE_COVERAGE}" = true ]; then
333333
done # end for each $PACK_PYTHON_DIR
334334
fi # end enable test coverage
335335

336-
PYTEST=(pytest)
337-
if head -n 1 $(command -v pytest) | grep -q ' -sE$'; then
338-
# workaround pants+pex default of hermetic scripts so we can run pytest with PYTHONPATH
339-
if [ -f "${STACKSTORM_VIRTUALENV_PYTHON_BINARY}" ]; then
340-
PYTEST=(${STACKSTORM_VIRTUALENV_PYTHON_BINARY} -m "pytest")
341-
else
342-
PYTEST=(python3 -m "pytest")
343-
fi
344-
fi
336+
PYTEST=(python3 -m pytest)
345337

346338
# Change to the pack's directory (required for test coverage reporting)
347339
pushd ${PACK_PATH} > /dev/null
348340

349341
# Execute the tests
350342
if [ "${TEST_LOCATION}" ]; then
351343
# Run a specific test file, class or method
352-
${PYTEST[@]} ${PYTEST_OPTS[@]} ${TEST_LOCATION}
344+
${PYTEST[@]} ${PYTEST_OPTS[@]} ${PACK_TESTS_PATH}${TEST_LOCATION}
353345
else
354346
# Run all tests inside the pack
355347
${PYTEST[@]} ${PYTEST_OPTS[@]} ${PACK_TESTS_PATH}

0 commit comments

Comments
 (0)