Pytest: Support py37's new breakpoint() function

Created on 1 Feb 2018  路  4Comments  路  Source: pytest-dev/pytest

Python 3.7 will have a new breakpoint() function to enter the debugger and pytest should play well with it.

debugging backward compatibility enhancement

All 4 comments

Help needed? (pleeeease can I implement this!)

@tonybaloney sure, please go ahead! 馃榿

This is my thinking:

  • Check for existence of breakpoint in builtins to determine if version of Python implements PEP553 https://www.python.org/dev/peps/pep-0553/#implementation this means that if PyPy/PyPy3 etc. later decide to do so we're not coupling to CPython. Add a "supports_breakpoint_builtin" module-level attribute in pytest.debugging
  • Set the breakpoint sys.breakpointhook to the custom Pdb class implemented in https://github.com/pytest-dev/pytest/blob/master/_pytest/debugging.py#L44 that way if a user just calls breakpoint() inside a test it will invoke the custom Pytest Pdb with the terminalwriter fixes.
  • The custom Pdb module should only be set as the system breakpointhook when the user hasn't set PYTHONBREAKPOINT. Otherwise the user may have wanted to override the debugger using the PYTHONBREAKPOINT environment variable.
  • Cleanup and reverse back to sys.__breakpointhook__ in https://github.com/pytest-dev/pytest/blob/master/_pytest/debugging.py#L32-L35
  • If the user sets PYTHONBREAKPOINT=0 then neither the normal Pdb or the custom one should be called on the occurence of an unhandled exception
  • If the user sets PYTHONBREAKPOINT = _a custom debugger_ then it should use that in instead of Custom PDB, unless they have specified --pdbcls

Sounds good. One thing to look out for is probably check that external plugins like pytest-ipdb will keep working, bonus points if they automatically support breakpoint as well.

Was this page helpful?
0 / 5 - 0 ratings