Created
July 29, 2020 14:08
-
-
Save davidhalter/799bf0ca3a109e1efa53df847cbf1a00 to your computer and use it in GitHub Desktop.
Pytest 5 Remote PDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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