Improve debug logs when running BDD tests

I've been spoilt by tools like Behat and so this make it much nicer
because it tells you exactly the feature/scenario/step where it failed.
This commit is contained in:
Dion Moult
2025-03-11 18:40:00 +11:00
parent 1e97d2c5fa
commit f08dba6483
2 changed files with 37 additions and 3 deletions
+19
View File
@@ -0,0 +1,19 @@
import pytest
# pytest by default doesn't print steps and where it failed. Let's fix that.
@pytest.hookimpl
def pytest_bdd_before_scenario(request, feature, scenario):
print(f"\033[94m# {feature.name}\033[0m")
print(f"\033[94m## {scenario.name}\033[0m")
@pytest.hookimpl(tryfirst=True)
def pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args):
print(f"\033[92m>>> {step.name}\033[0m")
@pytest.hookimpl(tryfirst=True)
def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args):
print(f"\033[1;91m>>> {step.name} <-- FAILED\033[0m")