Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py.test: Show local variables in Jenkins

Up to now we call py.test via Jenkins.

If a test fails, we see the usual stacktrace like this

Traceback (most recent call last):
  File "/home/u/src/foo/bar/tests/test_x.py", line 36, in test_schema_migrations
    errors, out))
AssertionError: Unknown output: ["Migrations for 'blue':", ...] 

It would be really great, if I could see local variables like in the django debug page (See https://djangobook.com/wp-content/uploads/figure2_3a.png).

.... But they should only be visible if I want to see them. I guess this means I need a different format than text. Maybe HTML?

Is there a way to enable this?

I never used the tool Sentry. But AFAIK this can display nice tracebacks with local variables.

like image 649
guettli Avatar asked Dec 06 '17 12:12

guettli


People also ask

How do I run pytest verbose?

Running pytest -vv should make your output more verbose. If you want your output to be less verbose, try pytest -q or pytest --quiet .

How do I run a specific test case in pytest?

Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .

What is Flag in pytest?

The -v flag controls the verbosity of pytest output in various aspects: test session progress, assertion details when tests fail, fixtures details with --fixtures , etc.


1 Answers

Use -l/--showlocals option:

pytest --showlocals # show local variables in tracebacks
pytest -l           # show local variables (shortcut)

example:

    def foo():
        a = 1
>       assert 0
E       assert 0

a          = 1

test_foo.py:8: AssertionError

see more details in the doc.

like image 103
georgexsh Avatar answered Oct 14 '22 13:10

georgexsh