From 21ada0fa23d20dcc2945ecb3f8ef5c62a96deac3 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Fri, 23 Mar 2018 14:20:10 +1100 Subject: [PATCH] add check for support of breakpoint() and use Custom Pdb class when system default is set --- _pytest/debugging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/_pytest/debugging.py b/_pytest/debugging.py index bb21a9e0e..f73a9a6b9 100644 --- a/_pytest/debugging.py +++ b/_pytest/debugging.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function import pdb import sys +import os from doctest import UnexpectedException try: @@ -33,12 +34,19 @@ def pytest_configure(config): if config.getvalue("usepdb"): config.pluginmanager.register(PdbInvoke(), 'pdbinvoke') + # Use custom Pdb class set_trace instead of default Pdb on breakpoint() call + if SUPPORTS_BREAKPOINT_BUILTIN: + _environ_pythonbreakpoint = getattr(os.environ, 'PYTHONBREAKPOINT', '') + if _environ_pythonbreakpoint == '': + sys.breakpointhook = pytestPDB.set_trace + old = (pdb.set_trace, pytestPDB._pluginmanager) def fin(): pdb.set_trace, pytestPDB._pluginmanager = old pytestPDB._config = None pytestPDB._pdb_cls = pdb.Pdb + sys.breakpointhook = sys.__breakpointhook__ pdb.set_trace = pytestPDB.set_trace pytestPDB._pluginmanager = config.pluginmanager