Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pdb.set_trace() with pytest-xdist #390

Closed
pytestbot opened this issue Nov 20, 2013 · 8 comments
Closed

support pdb.set_trace() with pytest-xdist #390

pytestbot opened this issue Nov 20, 2013 · 8 comments
Labels
plugin: xdist related to the xdist external plugin type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

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


@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

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.

@pytestbot
Copy link
Contributor Author

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!

@pytestbot
Copy link
Contributor Author

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.

@pytestbot pytestbot added type: enhancement new feature or API change, should be merged into features branch plugin: xdist related to the xdist external plugin labels Jun 15, 2015
@rbu
Copy link

rbu commented Jun 20, 2015

@rbuchholz is actually @rbu on GitHub

@RonnyPfannschmidt
Copy link
Member

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

@astockwell
Copy link

If you need to use PDB momentarily to troubleshoot, but don't want to rip out xdist, you can invoke it with the flags pytest -n0 --dist no which disables xdist entirely for that run (this also fixes the -s (stdout redirect) flag). Source: pytest-dev/pytest-xdist#231

@ralokt
Copy link

ralokt commented Jan 10, 2023

Also, if you need to use a debugger, and you actually need test distribution (for example, because you are debugging a xdist-heisenbug that only happens when tests are distributed), you can use a remote debugger! python-remote-debug just solved that issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: xdist related to the xdist external plugin type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

5 participants