From 298c3f8398da5bd5d8bdbe576e29f09e16449e18 Mon Sep 17 00:00:00 2001 From: wesleybl Date: Fri, 28 Nov 2025 14:19:30 -0300 Subject: [PATCH] Create target test We can use, for example: `make test package=plone.namedfile` or `make test package=plone.namedfile test=test_scaling` --- README-make.md | 18 ++++++++++++++++-- include.mk | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README-make.md b/README-make.md index f6e6d49399..0fd356928c 100644 --- a/README-make.md +++ b/README-make.md @@ -124,10 +124,24 @@ Run `make zope-start` to start the Zope instance. ### Run tests -This is not in the Makefile yet. We need to figure out how best to run the tests first. -A few sample commands that work for me: +Use the `make test` target to run unit tests for a package: +```bash +# Run all unit tests for a package (package is required) +make test package=plone.namedfile + +# Run a specific test +make test package=plone.namedfile test=test_scaling ``` + +The target automatically detects the correct path for: +- Packages in development with modern layout (`src/package/src/`) +- Packages in development with legacy layout (`src/package/`) +- Packages installed in the virtual environment + +You can also run tests directly with `zope-testrunner`: + +```bash .venv/bin/zope-testrunner --test-path src/Products.CMFPlone -u .venv/bin/zope-testrunner --test-path .venv/lib/python3.12/site-packages -s plone.memoize ``` diff --git a/include.mk b/include.mk index 8bef36af9c..4982ea5643 100644 --- a/include.mk +++ b/include.mk @@ -46,3 +46,32 @@ run-presources: $(PRE_SOURCES_TARGET) @touch $(PRE_SOURCES_TARGET) INSTALL_TARGETS+=run-presources + +############################################################################## +# test +############################################################################## + +# Usage: +# make test package=plone.namedfile +# make test package=plone.namedfile test=test_scaling +# +.PHONY: test +test: $(PACKAGES_TARGET) +ifndef package + $(error package is required. Usage: make test package=plone.namedfile [test=test_name]) +endif + $(eval TEST_PATH := $(shell \ + if [ -d "src/$(package)/src" ]; then \ + echo "src/$(package)/src"; \ + elif [ -d "src/$(package)" ]; then \ + echo "src/$(package)"; \ + else \ + .venv/bin/python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])"; \ + fi)) +ifdef test + @echo "Running test '$(test)' from package '$(package)' (path: $(TEST_PATH))" + @.venv/bin/zope-testrunner -u --test-path $(TEST_PATH) -s $(package) -t $(test) +else + @echo "Running all unit tests from package '$(package)' (path: $(TEST_PATH))" + @.venv/bin/zope-testrunner -u --test-path $(TEST_PATH) -s $(package) +endif