Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest assertion message not displayed in helper function within same test module in pycharm

Tags:

pycharm

pytest

I'm seeing that assertion messages do not seem to be displayed if the assertion occurs in a helper method within the same module as my test when in PyCharm.

This only seems to be happening in PyCharm - it does not happen when running from the command line.

This works:

def test_assertion_message_working():
  assert 1 == 2, "my message"
Expected :2
Actual :1
...
def test_assertion_message_working():
> assert 1 ==2, "my message"

But this doesn't (the test fails, but I do not get the failure message):

def test_assertion_message_not_working():
  do_assertion()

def do_assertion():
  assert 1 == 2, "my message"
1 != 2

Expected :2 
Actual :1
...
def test_assertion_not_working():
>  do_assertion()

Wondering if there is any setting (or workaround) I need to apply to get this working?

like image 549
Aconstnull Avatar asked Aug 07 '26 06:08

Aconstnull


1 Answers

Add the next additional flag to the run configuration Additional Arguments: --tb=short

You can edit the configuration templates to make it the default.

More info can be found here: https://youtrack.jetbrains.com/issue/PY-49150/pytest-output-in-PyCharm-lacks-information-about-assertion-failures-in-helper-methods

enter image description here

like image 99
mgershen Avatar answered Aug 10 '26 17:08

mgershen