[Pytest-commit] Issue #626: Add custom message to default assert repr (hpk42/pytest)

John Dennison issues-reply at bitbucket.org
Thu Oct 30 02:46:52 CET 2014


New issue 626: Add custom message to default assert repr
https://bitbucket.org/hpk42/pytest/issue/626/add-custom-message-to-default-assert-repr

John Dennison:

I asked a question on stackoverflow and was asked to add an issue for my use case so here i go: http://stackoverflow.com/questions/26620740/appending-to-default-py-test-assertion-output/26642915#26642915

I would like to add additional output to the default assertion failure output. 

I am able to over ride the output entirely with pytest_assertrepr_compare but i can't seem to get the default output and add my custom message to it. I have tried:

from _pytest.assertion.util import assertrepr_compare
def pytest_assertrepr_compare(config, op, left, right):
    pytest_output = assertrepr_compare(config, op, left, right)
    # append log output to normal compare, but the pytest_output is always None
    return pytest_output + ['THIS IS MY CUSTOM MESSAGE']

My actual use case is printing logs from remote servers when an assertion fails. If any of my tests fail. display the regular assertion failure and then my custom message.




More information about the pytest-commit mailing list