Skip to content

Instantly share code, notes, and snippets.

@davidhalter
Created July 29, 2020 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidhalter/799bf0ca3a109e1efa53df847cbf1a00 to your computer and use it in GitHub Desktop.
Save davidhalter/799bf0ca3a109e1efa53df847cbf1a00 to your computer and use it in GitHub Desktop.
Pytest 5 Remote PDB
import socket
import pdb
def pytest_addoption(parser):
parser.addoption("--remote-pdb", action='store_true',
help="Opens a remote pdb on localhost:8050. Works with xdist")
def pytest_exception_interact(node, call, report):
if node.config.option.remote_pdb:
tb = call.excinfo._excinfo[2]
remote_post_mortem(tb)
def remote_post_mortem(tb):
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
listen_socket.bind(('127.0.0.1', 8010))
listen_socket.listen(1)
connection, address = listen_socket.accept()
handle = connection.makefile('rw')
# Copied from pdb.post_mortem
p = pdb.Pdb(stdin=handle, stdout=handle)
p.reset()
p.interaction(None, tb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment