I added the coverage keyword and regular expression on stage, still not working.
run tests:
stage: test
coverage: '/coverage: ^TOTAL.+?(\d+\%)$/'
I added the coverage keyword and regular expression on stage, still not working.
run tests:
stage: test
coverage: '/coverage: ^TOTAL.+?(\d+\%)$/'
First, make sure your tests actually generate a coverage report in the expected format and output that to the console, as this is where GitLab CI fetches the coverage percentage from.
If the test suite already outputs a coverage report, then the issue could be the regex you are using. The coverage:
keyword expects a regex that matches the line in the job log that includes the coverage report.
I am not sure about coverage: ^TOTAL.+?(\d+\%)$
: the ^
(which asserts position at start of a line) generally is starting a regexp, not in the middle of one. Try and focus on TOTAL
, instead of what is before it)
For example:
run tests:
stage: test
coverage: '/TOTAL.+?(\d+\%)/'
The regex '/TOTAL.+?(\d+\%)/'
will match lines that contain "TOTAL" followed by any number of characters (.+?
), and then a number ending in "%" (\d+\%
). If the coverage report produced by your tests does not follow this format, you will need to adjust your regex accordingly.
Remember that your regular expression should match the exact line in your job logs where the coverage percentage is shown. It can be different for different testing tools. Here is an example for pytest-cov
:
run tests:
stage: test
coverage: '/TOTAL\s+(\d+\%)/'
You can test your regex using the job logs to ensure it matches the line with the coverage information correctly.