pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.31k stars 221 forks source link

hide pytest-bdd internal methods from tracebacks #555

Closed glehmann closed 2 years ago

glehmann commented 2 years ago

pytest offers a way to hide a method from the traceback generated in case of failure, by setting __tracebackhide__ to True in the method to exclude.

It makes a much tidier output, a bit like when not using pytest-bdd:

__________________________________________________________________ test_authenticated_access_to_the_application ___________________________________________________________________
.venv/lib/python3.10/site-packages/pytest_bdd/scenario.py:184: in scenario_wrapper
    _execute_scenario(feature, scenario, request)
.venv/lib/python3.10/site-packages/pytest_bdd/scenario.py:154: in _execute_scenario
    _execute_step_function(request, scenario, step, step_func)
.venv/lib/python3.10/site-packages/pytest_bdd/scenario.py:124: in _execute_step_function
    return_value = call_fixture_func(fixturefunc=step_func, request=request, kwargs=kwargs)
.venv/lib/python3.10/site-packages/_pytest/fixtures.py:891: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
tests/gui/step_defs/star_steps.py:36: in redirected_to_homepage
    assert False
E   AssertionError

becomes just:

__________________________________________________________________ test_authenticated_access_to_the_application ___________________________________________________________________
tests/gui/step_defs/star_steps.py:36: in redirected_to_homepage
    assert False
E   AssertionError

Would you be interested in a pull request that add this attribute to the internal methods in pytest-bdd?

youtux commented 2 years ago

Interesting, yes bring it on!