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
Enable coverage information generation for pytest tests with CMake #226
Enable coverage information generation for pytest tests with CMake #226
Conversation
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
d7b7860
to
30769b3
Compare
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
They were excluded before, but only because gtests didn't use --env or --append-end. Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Thanks for contributing this enhancement. I was wondering about the decision where certain parts of the logic are located in the patch. I few thoughts so far:
|
Yeah, like I mentioned above, I wasn't really sure about some of the choices made for the PR, so I really appreciate this feedback!
Sounds good. I wanted to make this a In any way, enabling coverage for CMake packages already requires build time flags (for C and C++).
Got it. Will address this soon. |
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
@dirk-thomas see new commits (to be squashed eventually, or I can just open a new PR if you prefer) Now with colcon/colcon-ros#101, |
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Thanks for the improvement. |
) * Enable coverage information generation for pytest tests with CMake Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Add comment about pytest-cov version requirement for --cov-branch Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Add --pytest-with-coverage to run_test.py and mention the env var Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Rename to AMENT_CMAKE_TEST_PYTEST_WITH_COVERAGE Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Fix missing quote Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Exclude gtests from pytest coverage explicitly They were excluded before, but only because gtests didn't use --env or --append-end. Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Append pytest-cov flags in ament_add_pytest_test() directly Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Fix ament_has_pytest_cov() Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Change default logic to avoid overriding CLI params Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Remove --cov-append pytest_cov option Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Simplify indentation Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Remove QUIET arg from ament_has_pytest_cov() Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Change ament_has_pytest_cov() to ament_get_pytest_cov_version() Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Do not return() if pytest_cov is not found in ament_add_pytest_test() Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Fix missing empty <options> argument Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Simplify pytest_cov version regex match Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Write pytest_cov results to test-specific directory Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> * Make sure to create test-specific pytest_cov directory Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
As described in this answers.ros.org question, I was looking to generate coverage information for Python tests in a CMake package. The
--pytest-with-coverage
colcon
option only applies to (pure) Python packages.I borrowed some code from https://github.com/colcon/colcon-core/blob/af7fa089962a9e9a35926734e17b00cfb4c780a6/colcon_core/task/python/test/pytest.py#L77-L108.
I'm open to suggestions to
AMENT_CMAKE_TEST_PYTEST_WITH_COVERAGE
. I couldn't find a way to pass additional arguments/flags from thectest
invocation (done bycolcon
) through to therun_test.py
script other than by using an environment variable.AMENT_CMAKE_CURRENT_SOURCE_DIR
build_base
in a more robust way