164: Debugging Python Test Failures with pytest
Test & Code14 Sep 2021

164: Debugging Python Test Failures with pytest

An overview of the pytest flags that help with debugging.
From Chapter 13, Debugging Test Failures, of Python Testing with pytest, 2nd edition.

pytest includes quite a few command-line flags that are useful for debugging.

We talk about thes flags in this episode.

Flags for selecting which tests to run, in which order, and when to stop:

  • -lf / --last-failed: Runs just the tests that failed last.
  • -ff / --failed-failed: Runs all the tests, starting with the last failed.
  • -x / --exitfirst: Stops the tests session afterEd: after?Author: yep the first failure.
  • --maxfail=num: Stops the tests after num failures.
  • -nf / --new-first: Runs all the tests, ordered by file modification time.
  • --sw / --stepwise: Stops the tests at the first failure. Starts the tests at the last failure next time.
  • --sw-skip / --stepwise-skip: Same as --sw, but skips the first failure.

Flags to control pytest output:

  • -v / --verbose Displays all the test names, passing or failing.
  • --tb=[auto/long/short/line/native/no] Controls the traceback style.
  • -l / --showlocals Displays local variables alongside the stacktrace.

Flags to start a command-line debugger:

  • --pdb Starts an interactive debugging session at the point of failure.
  • --trace Starts the pdb source-code debugger immediately when running each test.
  • --pdbcls Uses alternatives to pdb, such as IPython’s debugger with –-pdbcls=IPython.terminal.debugger:TerminalPdb.

This list is also found in Chapter 13 of Python Testing with pytest, 2nd edition.
The chapter is "Debugging Test Failures" and covers way more than just debug flags, while walking through debugging 2 test failures.


Links:




Denne episoden er hentet fra en åpen RSS-feed og er ikke publisert av Podme. Den kan derfor inneholde annonser.

Episoder(237)

238: So Long, and Thanks for All the Fish

238: So Long, and Thanks for All the Fish

A farewell to a fun 10 years.Also, I should have tested it better. :)In the audio I got the numbers wrong.  Doh!This is episode 238, not 237. Oh well.I'll still be around, of course, at:pythontest.com...

15 Aug 20252min

237: FastAPI Cloud - Sebastián Ramírez

237: FastAPI Cloud - Sebastián Ramírez

In this episode, Brian interviews Sebastián Ramírez, creator of FastAPI, about its rapid rise in developer popularity and the launch of FastAPI Cloud. Sebastian explains how FastAPI Cloud addresses de...

11 Aug 202536min

236: Git Tips for Testing - Adam Johnson

236: Git Tips for Testing - Adam Johnson

In this episode, host Brian Okken and guest Adam Johnson explore essential Git features, highlighted by Adam's updated book, "Boost Your Git DX." Key topics include "cherry picking" for selective comm...

30 Jul 202519min

235: pytest-django - Adam Johnson

235: pytest-django - Adam Johnson

In this episode, special guest Adam Johnson joins the show and examines pytest-django, a popular plugin among Django developers. He highlights its advantages over the built-in unittest framework, incl...

22 Jul 202519min

234: pytest-metadata - provides access to test session metadata

234: pytest-metadata - provides access to test session metadata

pytest-metadata is described as a plugin for pytest that provides access to test session metadata. That is such a humble description for such a massively useful plugin. If you're already using pytest-...

8 Mai 20256min

233: pytest-check - allow multiple failures per test

233: pytest-check - allow multiple failures per test

pytest-check is a pytest plugin that allows multiple failures per test.Normally, a test function will fail and stop running with the first failed assert. That's totally fine for tons of kinds of softw...

2 Mai 20258min

232: The role of AI in software testing - Anthony Shaw

232: The role of AI in software testing - Anthony Shaw

AI is helping people write code.  Tests are one of those things that some people don't like to write.   Can AI play a role in creating automated software tests?  Well, yes. But it's a nuanced yes.  An...

25 Apr 202556min

231: pytest-repeat - works fine on Python 3.14

231: pytest-repeat - works fine on Python 3.14

pytest-repeat is a pytest plugin that makes it easy to repeat a single test, or multiple tests, a specific number of times.  works fine on Python 3.14is tested on Python 3.9-3.14probably works fine st...

10 Apr 20257min

Populært innen Fakta

fastlegen
dine-penger-pengeradet
relasjonspodden-med-dora-thorhallsdottir-kjersti-idem
foreldreradet
treningspodden
jakt-og-fiskepodden
rss-kunsten-a-leve
mikkels-paskenotter
rss-strid-de-norske-borgerkrigene
hverdagspsyken
sinnsyn
fryktlos
gravid-uke-for-uke
rss-sarbar-med-lotte-erik
rss-var-forste-kaffe
kvallm
tomprat-med-gunnar-tjomlid
rss-impressions-2
rss-bak-luftfarten
laringsmiljo-i-skole-og-barnehage-uis-podkast