1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
"""
An example to show hwo tracebacks work with hlper functions.
We've got.
1. test -> helper -> helper -> check function
2. test -> helper -> helper -> check context manager -> assert
3. test -> check context manager -> helper -> helper -> assert
The 3rd option has the worst tb right now, as it doesn't show the helper functions.
Takeaway: Keep the context manager close to the assert.
Possible todo item: Maybe the pseudo-tb could inspect the incoming exception more.
"""
from pytest_check import check
# check.equal in helper
def helper_func():
helper2_func()
def helper2_func():
check.equal(1, 2, "custom")
def test_tb_func(check):
helper_func()
# ctx in helper
def helper_ctx():
helper2_ctx()
def helper2_ctx():
with check("check message"):
assert 1 == 2, "assert message"
def test_tb_ctx(check):
helper_ctx()
# ctx in test func, assert in helper
def helper_assert():
helper2_assert()
def helper2_assert():
assert 1 == 2, "assert message"
def test_tb_ctx_assert(check):
with check("check message"):
helper_assert()
|