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

Reset magic breaks with coverage report #127

Open
svaberg opened this issue Dec 4, 2019 · 2 comments
Open

Reset magic breaks with coverage report #127

svaberg opened this issue Dec 4, 2019 · 2 comments

Comments

@svaberg
Copy link

svaberg commented Dec 4, 2019

Hi all, I love your project!

I just noticed that the IPython %reset magic breaks the coverage report generated with

py.test -v --nbval-lax --cov .

I observe this even when it is only present in the first line of the first cell of the notebook. I made a small example notebook (attached) where the reported coverage varies between 0% and 100%.

This is with no %reset magic:

Name       Stmts   Miss  Cover
------------------------------
mylib.py       2      0   100%

and this is with one %reset magic in first code cell

Name       Stmts   Miss  Cover
------------------------------
mylib.py       2      2     0%

Do you think it would be possible to survive a %reset or must they be avoided?

@vidartf
Copy link
Collaborator

vidartf commented Feb 12, 2020

The coverage code relies on putting a variable in the global scope of the kernel (__cov). There might be a technical trick to do in nbval to ensure that would survive %reset, but I'm not sure. It might be possible to add some code in the notebook in question to avoid clearing this variable.

@svaberg
Copy link
Author

svaberg commented Feb 19, 2020

Thanks @vidartf. Doing a "soft" reset %reset -s does not delete underscore and double underscore prepended variables, so I will use %reset -sf instead of %reset -f. This should work as long as the notebooks do not depend on underscore variables being erased by the reset command and is enough for my needs.

I think it would be possible to survive a %reset by redefining the magic method so that it copies __cov before the reset and puts it back afterwards, I might give that approach a try as well.

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

No branches or pull requests

2 participants