Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README-make.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +127 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use generic shell syntax highlighter, don't use comments for instructions because they are low contrast in the rendered code block, and make it easier to copy-paste a single command.

Suggested change
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
Use the `make test` target to run unit tests for a package.
For example, run all unit tests for a given package.
```shell
make test package=plone.namedfile
```
Run a specific test in the given package.
```shell
make test package=plone.namedfile test=test_scaling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevepiercy We need to specify somewhere that the package parameter is required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wesleybl that's what line 135 does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 135 describes how to run only one test from a given package.

What I'm trying to say is that it's not possible to execute the command:

make test

it's necessary to pass the package:

make test package=plone.namedfile

See: https://github.com/plone/buildout.coredev/pull/1059/files#diff-35b89ef65700ec4da068cc82250d658677a5aaabec8b91e21d0d3e69987c949fR130

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand what you mean. Line 135 mentions "the given package", and is followed by line 138, which has the package parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wesleybl But the run-tests.sh script says it is supposed to be run using make test, and that made me realize you are adding a new test target even though there is already one: https://github.com/plone/buildout.coredev/blob/6.2/Makefile#L468

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, in version 6.1 it doesn't exist: https://github.com/plone/buildout.coredev/blob/6.1/Makefile

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it was added in #1020

It would be nice to have it for both 6.1 and 6.2, with the same implementation in both, and improve it to have a way to optionally run the tests for only one package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the target already accepts individual packages and tests:

https://github.com/plone/buildout.coredev/blob/6.2/Makefile#L468

I'll test it later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and actually the target in branch 6.2 doesn't support running only the tests from a specific package.

```

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
Comment on lines +138 to +140
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to capitalize a list item when it is not a sentence.

Suggested change
- Packages in development with modern layout (`src/package/src/`)
- Packages in development with legacy layout (`src/package/`)
- Packages installed in the virtual environment
- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```bash
```shell

.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
```
Expand Down
29 changes: 29 additions & 0 deletions include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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