Test coverage in buildout-less Plone 6

In Plone 5 I used a simple addition to buildout

parts =

recipe = zc.recipe.egg
eggs = coverage

And then my gitlab yml had something like

  - bin/coverage run bin/test -s ims.contacts
  - bin/coverage html
  - bin/coverage report

In Plone 6 I'm trying to go without zc.buildout, but having an issue. Here's my test script with zope-testrunner which works.

zope-testrunner --test-path=sources/ims.contacts

And the failing coverage script:

coverage run zope-testrunner --test-path=sources/ims.contacts
No file to run: '[full_path_to_instance]\zope-testrunner'

I don't know why it tries to treat it as a path. This is in Windows, but I get a similar error in my gitlab CI/CD which is CentOS Linux. I looked through some packages and comments here and it sounds like running zope-testrunner this way is typical post-buildout, but I haven't seen anything for coverage. I wonder, are people using something else for code coverage these days or maybe eschewing the whole concept? Ultimately it would be nice to have in my Gitlab CI/CD for some projects but it's not really that important.

You have the right idea, but you have to give coverage the path to the zope-testrunner script a different way.

When you run zope-testrunner directly, your shell resolves it to a path using the PATH environment variable.

When you use coverage run, the coverage command expects that you are passing it a path relative to the current directory, and does not try to resolve it using the PATH environment variable.

Try the -m flag instead, to find the code to run as a Python dotted module path:
coverage run -m zope.testrunner --test-path=sources/ims.contacts

1 Like