Hi,

2 ways come to mind

a) using print
b) using the == operator for the assertion and a assert_repr_compare hook
see http://pytest.org/latest/assert.html#defining-your-own-assertion-comparison

-- Ronny
On Sunday, March 2, 2014 11:36:56 PM CEST, Jurko Gospodnetić wrote:
   Hi all.

I was wondering if anyone can tell me the cleanest way to make assertions in a specific part of my test code (e.g. a specific test class or module) report some extra information on test failure?

I can add a regular assertion description string, and that displays the extra information but it also avoids regular pytest test failure result reporting which I would like to keep.

I can also print out the extra information directly to stdout/stderr - but that can be hard to read, especially if the test prints out other data as well.

Usage scenario:
---------------
Imagine a class for comparing two XML structures. That class maintains some context information that would be useful to print out when an XML mismatch is detected. For example, if it detects two nodes with different namespaces, you want it to: - report exactly which nodes these are and not just 'there exist two nodes with mismatched namespaces' - make this information available without the developer having to drop into the debugger

If possible, it would also be a great plus if this extra content could be integrated into the regular 'red' assertion failure information.

   Best regards,
     Jurko Gospodnetić

_______________________________________________
Pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to