Opening pdb shell on failed test under tox

George Shuklin
OpsOps
Published in
Mar 15, 2022

--

I start to work on feature for Molecule, and their tox configuration is too big for me to understand properly. One problem I found that I can’t control pytest.

After some thoughts and experiments I found a way to pass command line parameters to pytest.

Inside of their tox.ini file there is a line:

commands =
...
python -m pytest {env:_EXTRAS} {env:PYTEST_ADDOPTS:} {posargs}

Thas posargs is the thing I need. Turned out, it’s a tox feature.

Together with well-known trick of having -- to terminate special handing of options, we can pass whatever we want:

tox -e py -- --pdb -k exec

This passes --pdb -k exec directly to pytest.

As bonus, I can limit tests scope and run only tests I’m worried about (-k) instead of 400+ in a testsuite.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.