add check for support of breakpoint() and use Custom Pdb class when system default is set

This commit is contained in:
Anthony Shaw 2018-03-23 14:20:10 +11:00
parent a1ff758d0d
commit 21ada0fa23
No known key found for this signature in database
GPG Key ID: AB4A19AE1CE85744
1 changed files with 8 additions and 0 deletions

View File

@ -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