diff --git a/CHANGES.rst b/CHANGES.rst index 36458325..ae0b8c51 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changelog ========= +2.16.2 +------ + +- Fix FixtureDef signature for newer pytest versions (The-Compiler) +- Better error explanation for the steps defined outside of scenarios (olegpidsadnyi) + 2.16.1 ------ diff --git a/pytest_bdd/__init__.py b/pytest_bdd/__init__.py index e4e07ee3..756735d7 100644 --- a/pytest_bdd/__init__.py +++ b/pytest_bdd/__init__.py @@ -3,6 +3,6 @@ from pytest_bdd.steps import given, when, then from pytest_bdd.scenario import scenario, scenarios -__version__ = '2.16.1' +__version__ = '2.16.2' __all__ = [given.__name__, when.__name__, then.__name__, scenario.__name__, scenarios.__name__] diff --git a/pytest_bdd/feature.py b/pytest_bdd/feature.py index f9cd6aff..1003562e 100644 --- a/pytest_bdd/feature.py +++ b/pytest_bdd/feature.py @@ -287,6 +287,10 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True): continue mode = get_step_type(clean_line) or mode + if not scenario and prev_mode not in (types.BACKGROUND, types.GIVEN) and mode in types.STEP_TYPES: + raise exceptions.FeatureError( + "Step definition outside of a Scenario or a Background", line_number, clean_line, filename) + if strict_gherkin: if (self.background and not scenario and mode not in ( types.SCENARIO, types.SCENARIO_OUTLINE, types.GIVEN, types.TAG)): diff --git a/tests/feature/test_no_scenario.py b/tests/feature/test_no_scenario.py new file mode 100644 index 00000000..6b05f91b --- /dev/null +++ b/tests/feature/test_no_scenario.py @@ -0,0 +1,26 @@ +"""Test no scenarios defined in the feature file.""" + +import py +import textwrap + + +def test_no_scenarios(testdir): + """Test no scenarios defined in the feature file.""" + features = testdir.mkdir('features') + features.join('test.feature').write_text(textwrap.dedent(u""" + Given foo + When bar + Then baz + """), 'utf-8', ensure=True) + testdir.makepyfile(py.code.Source(""" + + from pytest_bdd import scenarios + + scenarios('features') + """)) + result = testdir.runpytest() + result.stdout.fnmatch_lines( + [ + '*FeatureError: Step definition outside of a Scenario or a Background.*', + ], + )