Merge pull request #185 from pytest-dev/fix156

Better error explanation for the steps defined outside of scenarios
This commit is contained in:
Florian Bruhin 2016-06-21 17:02:24 +02:00 committed by GitHub
commit 6bed671dcf
4 changed files with 37 additions and 1 deletions

View File

@ -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
------

View File

@ -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__]

View File

@ -287,6 +287,10 @@ class Feature(object):
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)):

View File

@ -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.*',
],
)