Pytest: support pdb.set_trace() with pytest-xdist

Created on 20 Nov 2013  路  6Comments  路  Source: pytest-dev/pytest

Originally reported by: Robert Buchholz (BitBucket: rbuchholz, GitHub: rbuchholz)


Given a test

#!python
...
    def test_should_not_create_duplicate_entries(self):
        from pdb import set_trace ; set_trace()
...

I get

#!shell
(virtualenv)2 rbu@localhost ~/code $ py.test
...
>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>
> some_test.py(48)test_should_not_create_duplicate_entries()
-> self.assert_increases_by(filler.fill, indexCache.query.count, 1)
(Pdb) c
................

(virtualenv)rbu@localhost ~/code $ py.test --looponfail  
...
>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>
> some_test.py(48)test_should_not_create_duplicate_entries()
-> self.assert_increases_by(filler.fill, indexCache.query.count, 1)
(Pdb) 
F...............
=================================== FAILURES ===================================
...
>           if self.quitting: raise BdbQuit
E           BdbQuit
################################ LOOPONFAILING #################################
...
############################# waiting for changes ##############################
### Watching:   /home/rbu/code
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

This is py.test version 2.4.2, imported from .../pytest-2.4.2-py2.7.egg/pytest.pyc
setuptools registered plugins:
pytest-xdist-1.9 at .../pytest_xdist-1.9-py2.7.egg/xdist/plugin.pyc


xdist enhancement

All 6 comments

_Original comment by_ holger krekel (BitBucket: hpk42, GitHub: hpk42):


It's a known limitations that pytest-xdist and --pdb or pdb.set_trace() don't work. The former will error out immediately.

_Original comment by_ Robert Buchholz (BitBucket: rbuchholz, GitHub: rbuchholz):


Hey Holger, thanks for the reply. I haven't found anything in the documentation or xdist's web/pypi page, so I did not know this whether was intentional or known.
Now we have it documented.

_Original comment by_ BitBucket: dwt, GitHub: dwt:


Uhm, nice to know that this is expected. Could you perhaps elaborate on why that is so? Could this be changed? Do you want this to change?

Thanks!

_Original comment by_ holger krekel (BitBucket: hpk42, GitHub: hpk42):


pytest-xdist manages a test slave process which collects and runs tests (at the control of the master process). However, it doesn't currently implement "stdout/stderr/stdin" forwarding. So it is this forwarding that is missing for making pdb() work. It's probably not very hard to implement this forwarding but requires understanding of execnet which is the underlying library for managing master-slave communication.

@rbuchholz is actually @rbu on GitHub

Closing as stalled, also this one is rather hard to do propperly

Was this page helpful?
0 / 5 - 0 ratings