respect strict_gherkin also for scenarios shortcut

This commit is contained in:
Anatoly Bubenkov 2015-06-20 23:55:27 +02:00
parent f4f0f99563
commit 2b96f61268
5 changed files with 16 additions and 10 deletions

View File

@ -1,7 +1,7 @@
Changelog
=========
2.12.1
2.12.2
------
- Make it possible to relax strict Gherkin scenario validation (bubenkoff)

View File

@ -3,6 +3,6 @@
from pytest_bdd.steps import given, when, then
from pytest_bdd.scenario import scenario, scenarios
__version__ = '2.12.1'
__version__ = '2.12.2'
__all__ = [given.__name__, when.__name__, then.__name__, scenario.__name__, scenarios.__name__]

View File

@ -151,7 +151,7 @@ def get_tags(line):
)
def get_features(paths):
def get_features(paths, **kwargs):
"""Get features for given paths.
:param list paths: `list` of paths (file or dirs)
@ -168,7 +168,7 @@ def get_features(paths):
features.extend(get_features(glob2.iglob(op.join(path, "**", "*.feature"))))
else:
base, name = op.split(path)
feature = Feature.get_feature(base, name)
feature = Feature.get_feature(base, name, **kwargs)
features.append(feature)
features.sort(key=lambda feature: feature.name or feature.filename)
return features

View File

@ -363,6 +363,7 @@ def scenarios(*feature_paths, **kwargs):
frame = inspect.stack()[1]
module = inspect.getmodule(frame[0])
base_path = get_fixture(module, "pytestbdd_feature_base_dir")
strict_gherkin = get_fixture(module, "pytestbdd_strict_gherkin")
abs_feature_paths = []
for path in feature_paths:
if not os.path.isabs(path):
@ -373,7 +374,7 @@ def scenarios(*feature_paths, **kwargs):
module_scenarios = frozenset(
(attr.__scenario__.feature.filename, attr.__scenario__.name)
for name, attr in module.__dict__.items() if hasattr(attr, '__scenario__'))
for feature in get_features(abs_feature_paths):
for feature in get_features(abs_feature_paths, strict_gherkin=strict_gherkin):
for scenario_name, scenario_object in feature.scenarios.items():
# skip already bound scenarios
if (scenario_object.feature.filename, scenario_name) not in module_scenarios:

View File

@ -6,7 +6,7 @@ import mock
import pytest
from pytest_bdd import scenario, given, when, then
from pytest_bdd import scenario, scenarios, given, when, then
from pytest_bdd.feature import FeatureError, features
from pytest_bdd import exceptions
@ -37,15 +37,20 @@ def then_nevermind():
]
)
@pytest.mark.parametrize('strict_gherkin', [True, False])
@pytest.mark.parametrize('multiple', [True, False])
@mock.patch('pytest_bdd.fixtures.pytestbdd_strict_gherkin', autospec=True)
def test_wrong(mocked_strict_gherkin, request, feature, scenario_name, strict_gherkin):
def test_wrong(mocked_strict_gherkin, request, feature, scenario_name, strict_gherkin, multiple):
"""Test wrong feature scenarios."""
mocked_strict_gherkin.return_value = strict_gherkin
def declare_scenario():
@scenario(feature, scenario_name)
def test_scenario():
pass
if multiple:
scenarios(feature)
else:
@scenario(feature, scenario_name)
def test_scenario():
pass
if strict_gherkin:
with pytest.raises(FeatureError):