Hide stack traces within assert_queries() from results.
Review Request #14387 — Created March 21, 2025 and updated
When
assert_queries()
reports mismatches, pytest would show stack
traces going intoassert_queries()
, with all the logic and docs shown.
This made for long and annoying stack traces.pytest, it turns out, has a handy
__tracebackhide__ = True
flag you
can set in any particular traceback frame context to prevent it from
showing up in stack traces. This needs to be as high up as possible to
take effect.Unfortunately, this can't merely be set in
assert_queries()
itself or
in a decorator applying toassert_queries()
, as the code needs to run
in the context manager's__exit__()
function. So instead, we need to
return an explicit context manager instance that sets it at the right
time.We now dynamically construct and return a context manager that sets this
at the right time. Right now, all this is constructed within
assert_queries()
. It may be worthwhile breaking this and the other
functions out into a dedicated and more public class down the road, but
it's unclear at this time if there's much real-world value in doing
that.
All unit tests pass.
Verified that query assertion results appeared with the
assert_queries()
call.
Summary | ID |
---|---|
95b235349406a9ed9f906dd46ee19e0f17f97947 |