Skip to content

breakpoint() support #4027

@asottile

Description

@asottile

From what I can tell, breakpoint() works even with reverting #3331 CC @tonybaloney

diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py
index f51dff37..b3d2ec8e 100644
--- a/src/_pytest/debugging.py
+++ b/src/_pytest/debugging.py
@@ -7,13 +7,6 @@ from doctest import UnexpectedException
 
 from _pytest.config import hookimpl
 
-try:
-    from builtins import breakpoint  # noqa
-
-    SUPPORTS_BREAKPOINT_BUILTIN = True
-except ImportError:
-    SUPPORTS_BREAKPOINT_BUILTIN = False
-
 
 def pytest_addoption(parser):
     group = parser.getgroup("general")
@@ -51,20 +44,12 @@ 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 = os.environ.get("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
-        if SUPPORTS_BREAKPOINT_BUILTIN:
-            sys.breakpointhook = sys.__breakpointhook__
 
     pdb.set_trace = pytestPDB.set_trace
     pytestPDB._pluginmanager = config.pluginmanager
diff --git a/testing/test_pdb.py b/testing/test_pdb.py
index 246f514b..aa65287e 100644
--- a/testing/test_pdb.py
+++ b/testing/test_pdb.py
@@ -4,9 +4,15 @@ import platform
 import os
 
 import _pytest._code
-from _pytest.debugging import SUPPORTS_BREAKPOINT_BUILTIN
 import pytest
 
+try:
+    breakpoint
+except NameError:
+    SUPPORTS_BREAKPOINT_BUILTIN = False
+else:
+    SUPPORTS_BREAKPOINT_BUILTIN = True
+
 
 _ENVIRON_PYTHONBREAKPOINT = os.environ.get("PYTHONBREAKPOINT", "")
 
def test():
    breakpoint()
    print('ohai')
$ pytest test.py --tb=native
============================= test session starts ==============================
platform linux -- Python 3.7.0, pytest-3.8.2.dev4+g4474beeb.d20180923, py-1.6.0, pluggy-0.7.1
rootdir: /tmp/pytest, inifile: tox.ini
collected 1 item                                                               

test.py 
>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>
> /tmp/pytest/test.py(3)test()
-> print('ohai')
(Pdb) list
  1  	def test():
  2  	    breakpoint()
  3  ->	    print('ohai')
[EOF]
(Pdb) c
ohai
.                                                                [100%]

=========================== 1 passed in 4.27 seconds ===========================
$ pytest testing/test_pdb.py 
============================= test session starts ==============================
platform linux -- Python 3.7.0, pytest-3.8.2.dev4+g4474beeb.d20180923, py-1.6.0, pluggy-0.7.1
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/tmp/pytest/.hypothesis/examples')
rootdir: /tmp/pytest, inifile: tox.ini
plugins: hypothesis-3.71.10
collected 42 items                                                             

testing/test_pdb.py ..........................................           [100%]

========================== 42 passed in 17.73 seconds ==========================

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions