-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CI/coverage: Fix addopts, migrate away from pytest-cov #5649
CI/coverage: Fix addopts, migrate away from pytest-cov #5649
Conversation
dc4d8a3
to
9f1d306
Compare
Just as a comment, for detailed background: Initially, using Now, that we have the configuration settings for the coverage tool in Before this PR, you could only:
With this PR applied, you can use these commands:
As a final test before commit or push: With or without this PR, to run all test and get/check coverage, you can do:
Running pre-commit is also what GitHub CI now does to run the tests:
|
Thanks stephenchengCloud, psafont and Ashwin for the approvals! For anyone who reads this has write permission and give the final approval: I'm looking for a final approval for this Python CI-only PR now. Feel free to suggest a good approver as well. This is only a small incremental update fix for Python CI We recently approved and merged two large PRs into feature/py3:
The idea for the latter is to be able to run one command (e.g. The initial approach that I merged in the process configures the Now, after testing it more, when I tried to run a single test file like Passing the directories using Instead, it's better to just use This fixes the issue of allowing to run only specific tests when that is needed. The collection of coverage data is moved from using The final part of the fix is to fix a problem in the configuration settings for Only |
pyproject.toml
Outdated
# For example: | ||
# coverage run -m pytest python3/tests/test_xenapi.py | ||
# Adding specific --cov options using addopts is not recommended as it would | ||
# require to use they pytest-cov plugin, which would conflict with the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they
-> the
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the typo which pointed by @minglumlu , thanks
9f1d306
to
d922db1
Compare
The failure is because 2 of the ocaml packages provided by the repository got removed. The feature branch needs to be rebased on top of the master branch |
Have raised a PR for syncing with the master branch. Please check #5665 |
pyproject.toml: - Don't use [tool.pytest.ini_options].addopts to pass test paths: addopts forces those options to be used every time pytest is run, which is very restrictive. Instead, use `coverage run` to configure coverage options, and support running specific tests by passing them as arguments to pytest: coverage run -m pytest python3/tests/test_xenapi.py .pre-commit-config.yaml: - No longer rely on [tool.pytest.ini_options].addopts to use pytest-cov. Instead, use `coverage run` to run pytest with coverage, and then `coverage xml` to get an xml coverage dump of the coverage, as well as `coverage html` to generate html for viewing coverage locally, and `coverage report` to generate a brief textual report of the coverage. This also improves the configuration to show the coverage report after the test results have been shown and not in the middle of it. Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
d922db1
to
0e72cb6
Compare
To: @stephenchengCloud and @liulinC: for you to review.
Cc: @ashwin9390 pre-review results with Ashwin:
-ra
(applied!)The motivation and purpose for this PR is to allow running
pytest
for a given file. Example:The expected result is to run only the tests in the given test case file (as shown above).
The unexpected (current) behaviour is that all tests are run.
Fix this issue by not forcing to run all tests using
addopts
:pyproject.toml:
[tool.pytest.ini_options].addopts
to pass test paths:addopts
forces those options to be used every time pytest is run, which is very restrictive. Instead, usecoverage run
to configure coverage options, and support running specific tests by passing them as arguments to pytest:coverage run -m pytest python3/tests/test_xenapi.py
.pre-commit-config.yaml:
No longer rely on
[tool.pytest.ini_options].addopts
to usepytest-cov
. Instead, usecoverage run
to run pytest with coverage, and thencoverage xml
to get an XML coverage dump of the coverage, as well ascoverage html
to generate html for viewing coverage locally, andcoverage report
to generate a brief textual report of the coverage.This improves the configuration to show the coverage report after the test results (and not in the middle of them).