Skip to content

Debugging pytest with multiple processing (pytest ‐n)

Daiane Iglesia Dolci edited this page Dec 5, 2023 · 1 revision

When you have multiple processing tests with pytest-xdist, the standard -s/--capture=no option does not work due to pytest-xdist's implementation. Additionally, debugging using PDB or any other debugger relying on standard I/O won't work in this context.

To address debugging challenges within worker processes, you can use remote debuggers such as python-remote-pdb. Follow these steps to employ remote debugging effectively:

Step 1: Integrate Remote PDB into Your Code

Include the following code snippet in your test suite to initiate a remote PDB session on the first available port:

from remote_pdb import set_trace
set_trace()  # The port number will be displayed in the logs

If you want to specify a particular host/port, use the following code:

from remote_pdb import RemotePdb
RemotePdb('127.0.0.1', 4444).set_trace()

Step 2: Start Remote Debugging Session

Once the remote PDB is integrated into your code, start the debugging session using the following command:

nc -C 127.0.0.1 4444

Make sure to replace 127.0.0.1 and 4444 with your specified host and port if you customise them in Step 1.

Finalizing the Debugging Session

Conclude your debugging session by exiting the debugger or pressing Control-c.

Home

Building locally
Tips

Install Frequently Asked Questions

Running on HPC

Users

Developers Notes

Minutes and agenda of Firedrake meetings


Policies and procedures

Gravity wave scaling

Merge Complex Sprint

Reading Group

Firedrake 2021 Planning Meetings
Clone this wiki locally