pytest: start a debugger on test failure

While refactoring some tests, I stumbled upon a really cool pytest feature I wish I had known about before: pytest has a command line argument (--pdb) that drops you into a pdb debug shell whenever a test fails. Really handy for inspecting the state of the test to figure out why it’s failing or why your assertion isn’t working as expected!

pytest --pdb # drops to debug shell on each test failure

There are more examples in the pytest docs, including --trace which drops you into a debug shell at the start of each test so you can step through it line by line.