pdb doesn't play nice with doctests.. this is a quick hack to fix that.
Project description
What does it do? Fixes line numbers so you can easily figure out where your doctest is failing, also fixes
the list command in pdb so it can properly list the source code for your doctest.
Other things may be broken so please send feedback.
add to your cat doctesttest.py
def foo(a):
"""
>>> foo(1)
2
>>> import pdb; pdb.set_trace()
>>> foo(2)
2
"""
return a + 1
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
# without doctestpdbhacks
echo >> python doctesttest.py
--Return--
> doctest @ doctesttest.py(5)?()->None
-> >>> import pdb; pdb.set_trace()
(Pdb) l
1 def foo(a):
2 """
3 >>> foo(1)
4 2
5 -> >>> import pdb; pdb.set_trace()
6 >>> foo(2)
7 2
8 """
9 return a + 1
10
11 def _test():
the list command in pdb so it can properly list the source code for your doctest.
Other things may be broken so please send feedback.
add to your
def foo(a):
"""
>>> foo(1)
2
>>> import pdb; pdb.set_trace()
>>> foo(2)
2
"""
return a + 1
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
# without doctestpdbhacks
--Return--
> doctest @ doctesttest.py(5)?()->None
-> >>> import pdb; pdb.set_trace()
(Pdb) l
1 def foo(a):
2 """
3 >>> foo(1)
4 2
5 -> >>> import pdb; pdb.set_trace()
6 >>> foo(2)
7 2
8 """
9 return a + 1
10
11 def _test():