Skip to content

Add python and cython file coverage #238

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

Merged
merged 13 commits into from
Feb 19, 2021

Conversation

vlad-perevezentsev
Copy link
Collaborator

@vlad-perevezentsev vlad-perevezentsev commented Jan 11, 2021

  1. Install the coverage package (temporary solutions).
conda install coverage
  1. Install dpctl.
  2. Enter the command in the console.
coverage run -m unittest dpctl.tests
  1. To show a report on the coverage results.
coverage report -m
  1. To create an annotated HTML listings with coverage results.
coverage html
  1. The htmlcov folder will appear in the root folder of the project.
  2. You need to open the file htmlcov/index.html to view the report in HTML format.
coverage erase  # Erase previously collected coverage data.
rm -rf htmlcov  # Delete the report folder.

@diptorupd
Copy link
Contributor

@vlad-perevezentsev Can you give me the full command of how you include the source files? I tried your steps by modifying Step 3 to coverage run --source=dpctl -m unittest dpctl.tests, but that does not show me the Cython coverage. Also, I want to exclude the test cases from the coverage report.

@vlad-perevezentsev
Copy link
Collaborator Author

@diptorupd
To cover cython files:
Enable the Cython plugin in the .coveragerc config file of your project:

[run]
plugins = Cython.Coverage

And compile your Cython modules with line tracing support. This can be done by putting the following two comment lines at the top of the modules that you want to trace:
#cython: linetrace=True
#distutils: define_macros=CYTHON_TRACE=1

That's a double opt-in. The first line instructs Cython to generate verbose line tracing code (and thus increase the size of the resulting C/C++ file), and the second line enables this code at C compile time, which will most likely slow down your program. You can also configure both settings globally in your setup.py script.
http://blog.behnel.de/posts/coverage-analysis-for-cython-modules.html

All the flags for the coverage command can be added to the .coveragerc file.
Add the --omit=dpctl/tests/* flag to the coverage run command to exclude test cases from coverage reports.

@PokhodenkoSA PokhodenkoSA merged commit d214f1a into IntelPython:master Feb 19, 2021
@PokhodenkoSA PokhodenkoSA mentioned this pull request Feb 19, 2021
@vlad-perevezentsev vlad-perevezentsev deleted the test_coverage branch June 20, 2023 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable test coverage
3 participants