Remove dependency on defining __file__
See original GitHub issueHi. I’m working on a custom pytest kernel for Jupyter Notebooks. It is simply a thin wrapper on the ipython3 kernel and uses your excellent package for all the heavy lifting.
My aim is to make using it transparent, meaning no extra code should be added by the user. I have used injection to achieve most of this goal with the sole exception of the __file__
variable. I have a very crude hack that works around this.
What I was wondering, however, was if it could be possible to remove the dependency on defining __file__
in the notebook.
In particular some way to leverage the fact that I have access to the code being passed in to do_execute()
in the kernel so can essentially store all the code in a string if ipytest
can digest that directly without having to parse the .ipynb file that it needs to be passed in using __file__
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
I like option 1, too, for similar reasons you mentioned. I implemented it in develop, you can give it a try by installing
ipytest==0.5.0b5
. To makeipytest
fallback on the temporary file, you need to enable thetempfile_fallback
option. My current setup reads:It would be great, if you could give it a try and report back, whether this fix solves the issue for you.
@detly after running with the
tempfile_fallback
option for a while now, I have been convinved. Mostly for symmetry reasons, I do not want to enable it by default (*). However, I added aautoconfig
function with more reasonable defaults (tempfile_fallback=True, magics=True, rewrite_asserts=True, addopts=['-q']
). Hopefully, this makes the library a bit smoother to use for you.For now the option is only available in the current beta release. You can test-drive it by installing it with
pip install ipytest==0.8.0b1
and then use:(*): Since magics cannot be turned off, they should be optional, but then some options are enabled per default, some are disabled.