Skip to content

Commit

Permalink
Merge pull request #791 from crim-ca/make-tests-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Jan 31, 2025
2 parents 747dbfb + d203d9a commit d8b2d24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
42 changes: 24 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,29 @@ ifeq ($(filter $(TEST_VERBOSITY),"--capture"),)
TEST_VERBOSITY := $(TEST_VERBOSITY) --capture tee-sys
endif
endif

TEST_PROFILE ?= true
ifneq ($(filter "$(TEST_PROFILE)","true"),)
override TEST_PROFILE_ARGS = --profile --profile-svg --pstats-dir "$(REPORTS_DIR)/profiling" --durations 100
endif

TEST_XARGS ?=
override TEST_XARGS := $(TEST_VERBOSITY) $(TEST_PROFILE_ARGS) $(TEST_XARGS)

# autogen tests variants with pre-install of dependencies using the '-only' target references
TESTS := unit func cli workflow online offline no-tb14 spec coverage
TESTS := $(addprefix test-, $(TESTS))

$(TESTS): test-%: install-dev test-%-only

define run_test =
$(eval $@_PYTEST_JUNIT = --junitxml "$(REPORTS_DIR)/test-results.xml")
$(eval $@_PYTEST_CASE = $(1))
$(eval $@_PYTEST_CMD = pytest tests ${$@_PYTEST_CASE} $(TEST_XARGS) ${$@__PYTEST_JUNIT})
@echo ">" '${$@_PYTEST_CMD}'
@bash -c '${$@_PYTEST_CMD}'
endef

.PHONY: test
test: clean-test test-all ## alias for 'test-all' target

Expand All @@ -398,57 +413,48 @@ test-all: install-dev test-only ## run all tests (including long running tests)
.PHONY: test-only
test-only: mkdir-reports ## run all tests but without prior validation of installed dependencies
@echo "Running all tests (including slow and online tests)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
--junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,)

.PHONY: test-unit-only
test-unit-only: mkdir-reports ## run unit tests (skip long running and online tests)
@echo "Running unit tests (skip slow and online tests)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "not slow and not online and not functional" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "not slow and not online and not functional")

.PHONY: test-func-only
test-func-only: mkdir-reports ## run functional tests (online and usage specific)
@echo "Running functional tests..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "functional" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "functional")

.PHONY: test-cli-only
test-cli-only: mkdir-reports ## run WeaverClient and CLI tests
@echo "Running CLI tests..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "cli" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "cli")

.PHONY: test-workflow-only
test-workflow-only: mkdir-reports ## run EMS workflow End-2-End tests
@echo "Running workflow tests..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "workflow" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "workflow")

.PHONY: test-online-only
test-online-only: mkdir-reports ## run online tests (running instance required)
@echo "Running online tests (running instance required)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "online" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "online")

.PHONY: test-offline-only
test-offline-only: mkdir-reports ## run offline tests (not marked as online)
@echo "Running offline tests (not marked as online)..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "not online" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "not online")

.PHONY: test-no-tb14-only
test-no-tb14-only: mkdir-reports ## run all tests except ones marked for 'Testbed-14'
@echo "Running all tests except ones marked for 'Testbed-14'..."
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-m "not testbed14" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-m "not testbed14")

.PHONY: test-spec-only
test-spec-only: mkdir-reports ## run tests with custom specification (pytest format) [make SPEC='<spec>' test-spec]
@echo "Running custom tests from input specification..."
@[ "${SPEC}" ] || ( echo ">> 'SPEC' is not set"; exit 1 )
@bash -c '$(CONDA_CMD) pytest tests $(TEST_VERBOSITY) $(TEST_XARGS) \
-k "${SPEC}" --junitxml "$(REPORTS_DIR)/test-results.xml"'
@$(call run_test,-k "${SPEC}")

.PHONY: test-smoke
test-smoke: docker-test ## alias to 'docker-test' executing smoke test of built docker images
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ path!=16.12.0,!=17.0.0 # patch pytest-shutil (https://github.com/man-group/pyte
pluggy>=0.7
pytest
pytest-httpserver>=1.0.7 # support werkzeug>=3
pytest-profiling
pytest-server-fixtures
#pytest-rerunfailures
pytest-retry
Expand Down

0 comments on commit d8b2d24

Please sign in to comment.