PEP 553 interactivity between `IPython.core.debugger.set_trace` and `python -m doctest` causes test failures
See original GitHub issueThe promises of PEP 553 are pretty cool and even mention IPython by name. This and this seem to suggest that IPython.terminal.debugger.set_trace
would be a good value for PYTHONBREAKPOINT
. Indeed it does work:
File:
# test_case.py
def test_foo():
one = "1"
breakpoint()
assert int(one) == 1
if __name__ == "__main__":
test_foo()
Run:
% PYTHONBREAKPOINT='IPython.core.debugger.set_trace' python test_case.py
> /Users/matt/Documents/dev/dycelib/test_case.py(5)test_foo()
3 one = "1"
4 breakpoint()
----> 5 assert int(one) == 1
6
7 if __name__ == "__main__":
ipdb> dir()
['one']
ipdb> one
'1'
ipdb> c
However, breakpoint
s in doctest
s don’t work with IPython.core.debugger.set_trace
. Consider:
# test_case.txt
>>> one = "1"
>>> breakpoint()
>>> int(one) == 1
True
This works:
% python -m doctest test_case.txt ; echo "exit code: ${?}"
--Return--
> <doctest test_case.txt[1]>(1)<module>()->None
-> breakpoint()
(Pdb) dir()
['__builtins__', '__name__', '__return__', 'one']
(Pdb) one
'1'
(Pdb) c
exit code: 0
Neat! Now try this:
% PYTHONBREAKPOINT='IPython.core.debugger.set_trace' python -m doctest test_case.txt ; echo "exit code: ${?}"
dir()
one
c
**********************************************************************
File "test_case.txt", line 3, in test_case.txt
Failed example:
breakpoint()
Expected nothing
Got:
--Return--
None
> <doctest test_case.txt[1]>(1)<module>()
----> 1 breakpoint()
ipdb> ['__builtins__', '__name__', '__return__', 'one']
ipdb> '1'
ipdb>
**********************************************************************
1 items had failures:
1 of 3 in test_case.txt
***Test Failed*** 1 failures.
exit code 1
Note that there is no interactivity or output until the end of the run (after typing c<RETURN>
). Also, for some reason, IPython’s output is being considered by the test itself, so the test fails.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
doctest — Test interactive Python examples — Python 3.11.1 ...
To perform regression testing by verifying that interactive examples from a test file or a test object work as expected. To write tutorial...
Read more >Python's doctest: Document and Test Your Code at Once
The doctest module is a lightweight testing framework that provides quick and straightforward test automation. It can read the test cases from ......
Read more >cpython/doctest.py at main - GitHub
line of output is "Test failed.". Run it with the -v switch instead: python M.py -v. and a detailed report of all examples...
Read more >Summary of Python tracker Issues - Mailing List Archive
#31606: [Windows] Tests failing on installed Python 3.7a1 on Windows ... #31353: Implement PEP 553 - built-in breakpoint()
Read more >How To Write Doctests in Python - DigitalOcean
Python's standard library comes equipped with a test framework module called doctest. The doctest module programmatically searches Python ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right. I edited my previous response to reflect that.
It does sort of. EDIT: Removed as redundant.