Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
------
Expand Down
2 changes: 1 addition & 1 deletion pytest_bdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__]
4 changes: 4 additions & 0 deletions pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
26 changes: 26 additions & 0 deletions tests/feature/test_no_scenario.py
Original file line number Diff line number Diff line change
@@ -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.*',
],
)