Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyTest: Interactive Output (instead of pure ASCII)

Tags:

python

pytest

How can I get expandable output from PyTest?

For example the local variables. It would be great if I could expand/collapse them depending on my need.

I think that's where the current text-output of PyTest reaches its limit.

The question: Is there a way to get an interactive output from PyTest?

With interactive I mean to be able to expand/collapse the local variables.

expand-on-demand

Above example is from the django debug page.

I would like to have such an interactive output if I run pytest.

My output looks like this:

pytest-output-text-only

like image 898
guettli Avatar asked Oct 27 '22 14:10

guettli


1 Answers

For achieving an output similar to the screenshot (which I assume is from a Django debugging session), you will need pytest and the pytest-html plugin.

You invoke pytest using this command line.

pytest --showlocals --html=report.html --self-contained-html testmodule/test.py

This will give you a HTML report with a nice overview of collapsible tests. Passing the argument --showlocals will also be reflected in the HTML report. All failed tests will show the local variable scope.

I created a small example repository with further instructions.

HTML report example

like image 115
buzz Avatar answered Nov 15 '22 06:11

buzz