Skip to content

Commit 3dc1899

Browse files
committed
Skip empty test directory in makefile and display failed components.
In the local and remote runner the unit file test were moved leaving a directory without tests. pytest raises error code 5 in this case which causes the unit-tests target to fail.
1 parent 85386ff commit 3dc1899

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

Makefile

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,22 +820,29 @@ unit-tests: requirements .unit-tests
820820
@echo
821821
@echo "----- Dropping st2-test db -----"
822822
@mongosh st2-test --eval "db.dropDatabase();"
823-
@failed=0; \
823+
@failed=(); \
824824
for component in $(COMPONENTS_TEST); do\
825-
echo "==========================================================="; \
826-
echo "Running tests in" $$component; \
827-
echo "-----------------------------------------------------------"; \
828-
. $(VIRTUALENV_DIR)/bin/activate; \
829-
ST2TESTS_REDIS_HOST=$(ST2TESTS_REDIS_HOST) \
830-
ST2TESTS_REDIS_PORT=$(ST2TESTS_REDIS_PORT) \
831-
pytest -rx --verbose \
832-
$$component/tests/unit || ((failed+=1)); \
833-
echo "-----------------------------------------------------------"; \
834-
echo "Done running tests in" $$component; \
835-
echo "==========================================================="; \
825+
if ls $$component/tests/unit/test_*.py 2>/dev/null >/dev/null; then \
826+
echo "==========================================================="; \
827+
echo "Running tests in" $$component; \
828+
echo "-----------------------------------------------------------"; \
829+
. $(VIRTUALENV_DIR)/bin/activate; \
830+
ST2TESTS_REDIS_HOST=$(ST2TESTS_REDIS_HOST) \
831+
ST2TESTS_REDIS_PORT=$(ST2TESTS_REDIS_PORT) \
832+
pytest -rx --verbose $$component/tests/unit; \
833+
RET=$$?; \
834+
test $$RET -eq 0 || failed+=($$component); \
835+
echo "-----------------------------------------------------------"; \
836+
echo "Done running tests in $$component ($$RET)"; \
837+
echo "==========================================================="; \
838+
else \
839+
echo "==========================================================="; \
840+
echo "Skip: no test files for $$component"; \
841+
echo "==========================================================="; \
842+
fi; \
836843
done; \
837-
echo pytest runs failed=$$failed; \
838-
if [ $$failed -gt 0 ]; then exit 1; fi
844+
echo "pytest runs failed=$${failed[@]}"; \
845+
if [[ $${#failed[@]} -gt 0 ]]; then exit 1; fi
839846

840847
.PHONY: .run-unit-tests-coverage
841848
ifdef INCLUDE_TESTS_IN_COVERAGE

0 commit comments

Comments
 (0)