Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Integration of IPython pdb

License

NotificationsYou must be signed in to change notification settings

gotcha/ipdb

Repository files navigation

https://codecov.io/gh/gotcha/ipdb/branch/master/graphs/badge.svg?style=flat

Use

ipdb exports functions to access theIPython debugger, which featurestab completion, syntax highlighting, better tracebacks, better introspectionwith the same interface as the pdb module.

Example usage:

importipdbipdb.set_trace()ipdb.set_trace(context=5)# will show five lines of code# instead of the default three lines# or you can set it via IPDB_CONTEXT_SIZE env variable# or setup.cfg fileipdb.pm()ipdb.run('x[0] = 3')result=ipdb.runcall(function,arg0,arg1,kwarg='foo')result=ipdb.runeval('f(1,2) - 3')

Arguments for set_trace

The set_trace function accepts context which will show as many lines of code as defined,and cond, which accepts boolean values (such as abc == 17) and will start ipdb'sinterface whenever cond equals to True.

Using configuration file

It's possible to set up context using a .ipdb file on your home folder, setup.cfgor pyproject.toml on your project folder. You can also set your file location viaenv var $IPDB_CONFIG. Your environment variable has priority over the homeconfiguration file, which in turn has priority over the setup config file.Currently, only context setting is available.

A valid setup.cfg is as follows

[ipdb]context=5

A valid .ipdb is as follows

context=5

A valid pyproject.toml is as follows

[tool.ipdb]context=5

The post-mortem function,ipdb.pm(), is equivalent to the magic function%debug.

If you installipdb with a tool which supportssetuptools entry points,anipdb script is made for you. You can use it to debug your python 2 scripts like

$ bin/ipdb mymodule.py

And for python 3

$ bin/ipdb3 mymodule.py

Alternatively with Python 2.7 only, you can also use

$ python -m ipdb mymodule.py

You can also enclose code with thewith statement to launch ipdb if an exception is raised:

fromipdbimportlaunch_ipdb_on_exceptionwithlaunch_ipdb_on_exception():    [...]

Warning

Context managers were introduced in Python 2.5.Adding a context manager implies dropping Python 2.4 support.Useipdb==0.6 with 2.4.

Or you can useiex as a function decorator to launch ipdb if an exception is raised:

fromipdbimportiex@iexdefmain():    [...]

Warning

Usingfrom future import print_function for Python 3 compat implies dropping Python 2.5 support.Useipdb<=0.8 with 2.5.

Issues withstdout

Some tools, likenose fiddle withstdout.

Untilipdb==0.9.4, we tried to guess when we should alsofiddle withstdout to support those tools.However, all strategies tried until 0.9.4 have proven brittle.

If you usenose or another tool that fiddles withstdout, you shouldexplicitly ask forstdout fiddling by usingipdb like this

importipdbipdb.sset_trace()ipdb.spm()fromipdbimportslaunch_ipdb_on_exceptionwithslaunch_ipdb_on_exception():    [...]

Development

ipdb source code and tracker are athttps://github.com/gotcha/ipdb.

Pull requests should take care of updating the changelogHISTORY.txt.

Under the unreleased section, add your changes and your username.

Manual testing

To test your changes, make use ofmanual_test.py. Create a virtual environment,install IPython and runpython manual_test.py and check if your changes are in effect.If possible, create automated tests for better behaviour control.

Automated testing

To run automated tests locally, create a virtual environment, install coverageand run coverage run setup.py test.

Third-party support

Products.PDBDebugMode

Zope2Products.PDBDebugMode usesipdb, if available, in place ofpdb.

iw.debug

iw.debug allows you to trigger anipdb debugger on any published objectof a Zope2 application.

ipdbplugin

ipdbplugin is anose test runner plugin that also uses the IPython debuggerinstead ofpdb. (It does not depend onipdb anymore).

pytest

pytest supports a--pdb option which can runipdb /IPython.terminal.debugger:Pdb onException andbreakpoint():

pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb -v ./test_example.py

You don't need to specify--pdbcls for everypytest invocationif you addaddopts topytest.ini orpyproject.toml.

pytest.ini:

[tool.pytest.ini_options]addopts ="--pdbcls=IPython.terminal.debugger:Pdb"

pyproject.toml:

[tool.pytest.ini_options]addopts = "--pdbcls=IPython.terminal.debugger:Pdb"

[8]ページ先頭

©2009-2025 Movatter.jp