Skip to content
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

Add a coverage plugin that handles ipykernel cells #110

Merged
merged 18 commits into from
Apr 16, 2024
Merged

Conversation

chmp
Copy link
Owner

@chmp chmp commented Apr 15, 2024

Open issues:

  • how to inject the coverage plugin with a coveragerc file?
    • document the standard way (using .coveragerc)
  • how to get coverage to not ignore the (non-existing) kernel directory?
    • For cell files of such as C:/Users/{USER}/AppData/Local/Temp/ipykernel_1300/3920661193.py, C:/Users/{USER}/AppData/Local/Temp works, C:/Users/{USER}/AppData/Local/Temp/ipykernel_1300 does not
    • theory this behavior is triggered by this line
    • A: without explicit source, this issue does not come up
  • Another issue is that %%ipytest --cov gets completed to %%ipytest --cov {MODULE}. Therefore {MODULE} is added to the sources. Using %%ipytest --cov -vv works correctly.
    • A: insert a -- in the defopts to make sure the inserted module is never parsed an argument value

Notes:

  • ipykernel uses a custom caching compiler (source)
  • this caching compiler uses a file of the format {TMP_PATH}/ipykernel_{pid}/{code_hash}.py (source)

@chmp chmp marked this pull request as ready for review April 16, 2024 18:57
@chmp chmp merged commit 8cbf1c1 into main Apr 16, 2024
1 check passed
@chmp chmp deleted the feature/coverage-support branch April 16, 2024 19:00
Copy link

@westurner westurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Line and Branch Coverage help check code quality.

Common misconception: if something has 100% test coverage, it's also fuzzed.

also, re: hypothesis property testing and pytest-cov: https://hypothesis.readthedocs.io/en/latest/strategies.html#interaction-with-pytest-cov

ipytest/cov.py Show resolved Hide resolved
plugins =
ipytest.cov
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %%file cell magic can be used to create files like .coveragerc from a notebook.

%%file .coveragerc
[run]
plugins =
    ipytest.cov

Would an ipytest.generate_coveragerc() or similar be too much? or Just autoconfig(coverage=True) or something?

Copy link
Owner Author

@chmp chmp Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH. I would rather prefer, that there is an option to configure pytest-cov programatically and inject the plugin in that way. I will open an issue for further discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants