From 771f263ec6fc90334e16ff6aaf7195b6ce17cbda Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Thu, 18 Sep 2014 18:32:50 +0000 Subject: [PATCH] Better reporting of a not found scenario --- CHANGES.rst | 6 ++++++ pytest_bdd/scenario.py | 5 ++++- tests/feature/test_scenario.py | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 64a0766..a55044d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changelog ========= +Unreleased +---------- + +- Better reporting of a not found scenario (bubenkoff) + + 2.4.0 ----- diff --git a/pytest_bdd/scenario.py b/pytest_bdd/scenario.py index b2b9cb9..3697105 100644 --- a/pytest_bdd/scenario.py +++ b/pytest_bdd/scenario.py @@ -263,7 +263,10 @@ def scenario( scenario = feature.scenarios[scenario_name] except KeyError: raise exceptions.ScenarioNotFound( - 'Scenario "{0}" in feature "{1}" is not found.'.format(scenario_name, feature_name) + 'Scenario "{scenario_name}" in feature "{feature_name}" in {feature_filename} is not found.'.format( + scenario_name=scenario_name, + feature_name=feature.name or '[Empty]', + feature_filename=feature.filename) ) scenario.example_converters = example_converters diff --git a/tests/feature/test_scenario.py b/tests/feature/test_scenario.py index ea4bfe3..a7c4e39 100644 --- a/tests/feature/test_scenario.py +++ b/tests/feature/test_scenario.py @@ -8,11 +8,13 @@ from pytest_bdd import exceptions def test_scenario_not_found(request): """Test the situation when scenario is not found.""" - with pytest.raises(exceptions.ScenarioNotFound): + with pytest.raises(exceptions.ScenarioNotFound) as exc_info: scenario( 'not_found.feature', 'NOT FOUND' ) + assert exc_info.value.args[0].startswith('Scenario "NOT FOUND" in feature "[Empty]" in {feature_path}'.format( + feature_path=request.fspath.join('..', 'not_found.feature'))) def test_scenario_comments(request):