Closed tamuhey closed 4 years ago
Thanks for the feedback and brining this issue up. First, you're right atm I can't think of way to run doctests with pytest and ipytest. I had a quick look into how that part of the code is implemented and fixing it does not seem to be easy.
Maybe as a short-time solution, the non-pytest way to execute doc tests should work:
import doctest
doctest.testmod()
Documenting the "solution" for myself, while pondering, whether this hack is a good idea:
def _run_impl(*args, module, filename, plugins, return_exit_code):
...
with _valid_filename(filename, module) as valid_filename:
import sys, pathlib
p = pathlib.Path(valid_filename)
sys.modules[p.stem] = module
module.__file__ = str(p.with_suffix(".py"))
...
The reason this works:
__file__
attribute of the imported module with the filenameRemarks:
I added a new config option register_module
if set to True
doctests will work as expected:
import ipytest
ipytest.autoconfig(register_module=True)
%%run_pytest --doctest-modules
def foo(x):
"""
>>> foo(2)
4
"""
return x*2
This functionality will be released with the 0.9.0
.
Hi, thanks for this great project!
I want to run doctest with cell magic, as follows:
However, the output says no tests found: