Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Created June 26, 2018 09:25
Show Gist options
  • Save mattbennett/9dd456f31e1161348e936b9c3a6918b9 to your computer and use it in GitHub Desktop.
Save mattbennett/9dd456f31e1161348e936b9c3a6918b9 to your computer and use it in GitHub Desktop.
Attach PDB to Nameko worker exceptions
@pytest.yield_fixture
def pdb_worker_exceptions():
import pdb
from mock import patch
from nameko.containers import ServiceContainer
unpatched = ServiceContainer._worker_result
def attach_pdb(self, worker_ctx, result, exc_info):
if exc_info:
pdb.post_mortem(exc_info[2])
return unpatched(self, worker_ctx, result, exc_info)
with patch.object(ServiceContainer, '_worker_result', new=attach_pdb):
yield
@mattbennett
Copy link
Author

You must run pytest with output capturing enabled (-s) in order to use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment