On error (such as AssertionError), tests will output error at bottom of all other "debug print" output. This is done via "intercepting" error, printing if it has not yet been displayed, then re-invoking original error handling.
This is done because otherwise, PyTest will print the original error at the top of testing output, and THEN display all our "debug print" output. So with tests of any real size, the original error will be hidden and require significant scrolling, just to see why the test even failed in the first place.
By intercepting the error and printing again, we manually display the error at the bottom, after all other "debug print" output. So the error that caused the failure is always immediately visible, regardless of how much other "debug print" output occurred.
Initially to accomplish this, we wanted to come up with a way to generically and dynamically add this to all applicable test functions. Our first attempt was to consider using Python MetaClasses (see https://realpython.com/python-metaclasses/ ). However, initial attempts did not provide any results. These attempts are scattered in the various "debug_print" branches that exist, as of writting this issue.
The current work-around (and only other way we know of to accomplish this, without potentially using a MetaClass) is to redefine literally every possible testing Assertion, add logic to handle this "error interception" logic, and then return the original Assertion handling.
I very much don't like this implementation, and feel like it's a kinda hacky work-around. But at least the "debug print" output is visually clean for the moment. Will keep tinkering around, hoping to find a better solution in the future.
On error (such as AssertionError), tests will output error at bottom of all other "debug print" output. This is done via "intercepting" error, printing if it has not yet been displayed, then re-invoking original error handling.
This is done because otherwise, PyTest will print the original error at the top of testing output, and THEN display all our "debug print" output. So with tests of any real size, the original error will be hidden and require significant scrolling, just to see why the test even failed in the first place.
By intercepting the error and printing again, we manually display the error at the bottom, after all other "debug print" output. So the error that caused the failure is always immediately visible, regardless of how much other "debug print" output occurred.
Initially to accomplish this, we wanted to come up with a way to generically and dynamically add this to all applicable test functions. Our first attempt was to consider using Python MetaClasses (see https://realpython.com/python-metaclasses/ ). However, initial attempts did not provide any results. These attempts are scattered in the various "debug_print" branches that exist, as of writting this issue.
The current work-around (and only other way we know of to accomplish this, without potentially using a MetaClass) is to redefine literally every possible testing Assertion, add logic to handle this "error interception" logic, and then return the original Assertion handling.
I very much don't like this implementation, and feel like it's a kinda hacky work-around. But at least the "debug print" output is visually clean for the moment. Will keep tinkering around, hoping to find a better solution in the future.