pytest-bdd/tests/feature/test_scenarios.py

94 lines
2.7 KiB
Python

"""Test scenarios shortcut."""
import textwrap
def test_scenarios(testdir, pytest_params, bdd_parser):
"""Test scenarios shortcut (used together with @scenario for individual test override)."""
testdir.makeini(
"""
[pytest]
console_output_style=classic
bdd_parser={bdd_parser}
""".format(
bdd_parser=bdd_parser
)
)
testdir.makeconftest(
"""
import pytest
from pytest_bdd import given
@given('I have a bar')
def _():
print('bar!')
return 'bar'
"""
)
features = testdir.mkdir("features")
features.join("test.feature").write_text(
textwrap.dedent(
"""\
Feature: A feature
Scenario: Test scenario
Given I have a bar
"""
),
"utf-8",
ensure=True,
)
features.join("subfolder", "test.feature").write_text(
textwrap.dedent(
"""\
Feature: Subfolder
Scenario: Test subfolder scenario
Given I have a bar
Scenario: Test failing subfolder scenario
Given I have a failing bar
Scenario: Test already bound scenario
Given I have a bar
Scenario: Test scenario
Given I have a bar
"""
),
"utf-8",
ensure=True,
)
testdir.makepyfile(
"""
import pytest
from pytest_bdd import scenarios, scenario
@scenario('features/subfolder/test.feature', 'Test already bound scenario')
def test_already_bound():
pass
scenarios('features')
"""
)
result = testdir.runpytest_subprocess("-v", "-s", *pytest_params)
result.assert_outcomes(passed=4, failed=1)
result.stdout.fnmatch_lines(["*collected 5 items"])
result.stdout.fnmatch_lines(["*test_test_subfolder_scenario *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_failing_subfolder_scenario *FAILED"])
result.stdout.fnmatch_lines(["*test_already_bound *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario_1 *bar!", "PASSED"])
def test_scenarios_none_found(testdir, pytest_params):
"""Test scenarios shortcut when no scenarios found."""
testpath = testdir.makepyfile(
"""
import pytest
from pytest_bdd import scenarios
scenarios('.')
"""
)
result = testdir.runpytest_subprocess(testpath, *pytest_params)
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(["*NoScenariosFound*"])