PyCharm: Show local variables after exception in “Run”

Most of the time I spent in PyCharm is executing tests with "Run" (shift-F10).

If the test fails with an exception, then it would be very nice if I could see/inspect the local variables.


Traceback (most recent call last):
  File "/home/x_vums/src/dt/dt/tests/", line 150, in test_quotes_can_miss
    lines = list(cutils.read_c(string=t))
  File "/home/x_vums/src/dt/dt/utils/", line 616, in read_c
    coln = [col.strip(quote_char + b' ') for col in splitted]
  File "/home/x_vums/src/dt/dt/utils/", line 616, in <listcomp>
    coln = [col.strip(quote_char + b' ') for col in splitted]
TypeError: must be str, not bytes

In above example I would like to inspect which variable is a string and which is are bytes.

I know how to debug in PyCharm, but "Run" is faster "Debug".

Comment actions Permalink

You must debug the script/test if you want to inspect variables, and it's expected to be slower than run (but not significantly slower, depends on your script). There's no other way I'm afraid.

Comment actions Permalink

How to improve the current situation?

It would be great if future PyCharm version have this feature.

Comment actions Permalink

You can submit a feature request to implement variable viewer for test runners.

Meanwhile you can use another approach, for example using sys._getframe

import sys

def foo():
a = 1
b = 2
frame = sys._getframe()


This way you can print variables, iterate over them e.t.c.


Please sign in to leave a comment.