parent
76ed2ece2a
commit
bfefabeb27
15
README.rst
15
README.rst
|
@ -54,8 +54,10 @@ publish_article.feature:
|
|||
Scenario: Publishing the article
|
||||
Given I'm an author user
|
||||
And I have an article
|
||||
|
||||
When I go to the article page
|
||||
And I press the publish button
|
||||
|
||||
Then I should not see the error message
|
||||
And the article should be published # Note: will query the database
|
||||
|
||||
|
@ -150,6 +152,7 @@ default author.
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Resource owner
|
||||
Scenario: I'm the author
|
||||
Given I'm an author
|
||||
And I have an article
|
||||
|
@ -174,6 +177,7 @@ pass optional ``scope`` argument:
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Fixture scope
|
||||
Scenario: I'm the author
|
||||
Given I'm an author
|
||||
And there is an article
|
||||
|
@ -257,6 +261,7 @@ Example:
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Step arguments
|
||||
Scenario: Arguments for given, when, thens
|
||||
Given there are 5 cucumbers
|
||||
|
||||
|
@ -367,6 +372,7 @@ it will stay untouched. To allow this, special parameter `target_fixture` exists
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Target fixture
|
||||
Scenario: Test given fixture injection
|
||||
Given I have injecting given
|
||||
Then foo should be "injected foo"
|
||||
|
@ -384,6 +390,7 @@ But in much cleaner and powerful way:
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Multiline steps
|
||||
Scenario: Multiline step using sub indentation
|
||||
Given I have a step with:
|
||||
Some
|
||||
|
@ -489,6 +496,7 @@ Example:
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Scenario outlines
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
|
@ -503,6 +511,7 @@ pytest-bdd feature file format also supports example tables in different way:
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Scenario outlines
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
|
@ -782,6 +791,8 @@ This also declares a PyTest fixture "article" and any other step can depend on i
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Power of pytest
|
||||
Scenario: Symbolic name across steps
|
||||
Given I have a beautiful article
|
||||
When I publish this article
|
||||
|
||||
|
@ -831,6 +842,8 @@ no sense. It won't be executed second time.
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Power of pytest
|
||||
Scenario: Given is a fixture and evaluated only once
|
||||
Given I have a beautiful article
|
||||
And some other thing
|
||||
And I have a beautiful article # Won't be executed, exception is raised
|
||||
|
@ -842,6 +855,8 @@ patterns to get arguments.
|
|||
|
||||
.. code-block:: gherkin
|
||||
|
||||
Feature: Power of pytest
|
||||
Scenario: Given is a fixture and evaluated only once
|
||||
Given I have 1 cucumbers
|
||||
And I have 2 cucumbers # Exception is raised
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ provided in the pytest parametrization table.
|
|||
|
||||
Syntax example:
|
||||
|
||||
Feature: Articles
|
||||
Scenario: Publishing the article
|
||||
Given I'm an author user
|
||||
And I have an article
|
||||
|
|
|
@ -1,10 +1 @@
|
|||
"""Configuration for pytest runner."""
|
||||
|
||||
from pytest_bdd import when
|
||||
|
||||
pytest_plugins = "pytester"
|
||||
|
||||
|
||||
@when("I use a when step from the parent conftest")
|
||||
def global_when():
|
||||
pass
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 12 | 5 | 7 |
|
||||
| 5 | 4 | 1 |
|
||||
|
||||
|
||||
Scenario Outline: Outlined with wrong examples
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left | unknown_param |
|
||||
| 12 | 5 | 7 | value |
|
||||
|
||||
|
||||
Scenario Outline: Outlined with some examples failing
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 0 | 5 | 5 |
|
||||
| 12 | 5 | 7 |
|
||||
|
||||
|
||||
Scenario Outline: Outlined with vertical example table
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples: Vertical
|
||||
| start | 12 | 2 |
|
||||
| eat | 5 | 1 |
|
||||
| left | 7 | 1 |
|
||||
|
||||
|
||||
Scenario Outline: Outlined with empty example values vertical
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples: Vertical
|
||||
| start | # |
|
||||
| eat | |
|
||||
| left | |
|
||||
|
||||
|
||||
Scenario Outline: Outlined with empty example values
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| # | | |
|
|
@ -1,16 +0,0 @@
|
|||
Feature: Outline
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 12 | 5 | 7 |
|
||||
| 5 | 4 | 1 |
|
||||
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> <fruits>
|
||||
When I eat <eat> <fruits>
|
||||
Then I should have <left> <fruits>
|
||||
|
||||
Examples:
|
||||
| fruits |
|
||||
| oranges |
|
||||
| apples |
|
|
@ -54,6 +54,7 @@ def prepare_testdir(testdir, ini_base_dir):
|
|||
feature_file = testdir.mkdir("features").join("steps.feature")
|
||||
feature_file.write(
|
||||
"""
|
||||
Feature: Feature path
|
||||
Scenario: When scenario found
|
||||
Given found
|
||||
"""
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
"""Scenario Outline tests."""
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from pytest_bdd import given, when, then, scenario
|
||||
from pytest_bdd import exceptions
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
|
||||
|
||||
@scenario("outline.feature", "Outlined given, when, thens", example_converters=dict(start=int, eat=float, left=str))
|
||||
def test_outlined(request):
|
||||
assert get_parametrize_markers_args(request.node) == (["start", "eat", "left"], [[12, 5.0, "7"], [5, 4.0, "1"]])
|
||||
STEPS = """\
|
||||
from pytest_bdd import given, when, then
|
||||
|
||||
|
||||
@given("there are <start> cucumbers")
|
||||
|
@ -34,30 +25,106 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
|
|||
assert start_cucumbers["start"] == start
|
||||
assert start_cucumbers["eat"] == eat
|
||||
|
||||
"""
|
||||
|
||||
def test_wrongly_outlined(request):
|
||||
|
||||
def test_outlined(testdir):
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 12 | 5 | 7 |
|
||||
| 5 | 4 | 1 |
|
||||
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario(
|
||||
"outline.feature",
|
||||
"Outlined given, when, thens",
|
||||
example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_outline(request):
|
||||
assert get_parametrize_markers_args(request.node) == (
|
||||
["start", "eat", "left"],
|
||||
[
|
||||
[12, 5.0, "7"],
|
||||
[5, 4.0, "1"],
|
||||
],
|
||||
)
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
def test_wrongly_outlined(testdir):
|
||||
"""Test parametrized scenario when the test function lacks parameters."""
|
||||
with pytest.raises(exceptions.ScenarioExamplesNotValidError) as exc:
|
||||
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined with wrong examples
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left | unknown_param |
|
||||
| 12 | 5 | 7 | value |
|
||||
|
||||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario("outline.feature", "Outlined with wrong examples")
|
||||
def wrongly_outlined():
|
||||
def test_outline(request):
|
||||
pass
|
||||
|
||||
assert re.match(
|
||||
r"""Scenario \"Outlined with wrong examples\" in the feature \"(.+)\" has not valid examples\. """
|
||||
r"""Set of step parameters (.+) should match set of example values """
|
||||
r"""(.+)\.""",
|
||||
exc.value.args[0],
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(error=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
'*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*has not valid examples*',
|
||||
)
|
||||
result.stdout.fnmatch_lines("*should match set of example values [[]'eat', 'left', 'start', 'unknown_param'[]].*",)
|
||||
|
||||
|
||||
def test_wrong_vertical_examples_scenario(testdir):
|
||||
"""Test parametrized scenario vertical example table has wrong format."""
|
||||
features = testdir.mkdir("features")
|
||||
feature = features.join("test.feature")
|
||||
feature.write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined with wrong vertical example table
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
|
@ -69,28 +136,34 @@ def test_wrong_vertical_examples_scenario(testdir):
|
|||
| left | 7 | 1 |
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
with pytest.raises(exceptions.FeatureError) as exc:
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
@scenario(feature.strpath, "Outlined with wrong vertical example table")
|
||||
def wrongly_outlined():
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario("outline.feature", "Outlined with wrong vertical example table")
|
||||
def test_outline(request):
|
||||
pass
|
||||
|
||||
assert exc.value.args[0] == (
|
||||
"Scenario has not valid examples. Example rows should contain unique parameters."
|
||||
' "start" appeared more than once'
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(error=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
"*Scenario has not valid examples. Example rows should contain unique parameters. "
|
||||
'"start" appeared more than once.*'
|
||||
)
|
||||
|
||||
|
||||
def test_wrong_vertical_examples_feature(testdir):
|
||||
"""Test parametrized feature vertical example table has wrong format."""
|
||||
features = testdir.mkdir("features")
|
||||
feature = features.join("test.feature")
|
||||
feature.write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outlines
|
||||
|
||||
Examples: Vertical
|
||||
|
@ -104,63 +177,166 @@ def test_wrong_vertical_examples_feature(testdir):
|
|||
Then I should have <left> cucumbers
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
with pytest.raises(exceptions.FeatureError) as exc:
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
@scenario(feature.strpath, "Outlined with wrong vertical example table")
|
||||
def wrongly_outlined():
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario("outline.feature", "Outlined with wrong vertical example table")
|
||||
def test_outline(request):
|
||||
pass
|
||||
|
||||
assert exc.value.args[0] == (
|
||||
"Feature has not valid examples. Example rows should contain unique parameters."
|
||||
' "start" appeared more than once'
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(error=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
"*Feature has not valid examples. Example rows should contain unique parameters. "
|
||||
'"start" appeared more than once.*'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def other_fixture(request):
|
||||
def test_outlined_with_other_fixtures(testdir):
|
||||
"""Test outlined scenario also using other parametrized fixture."""
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 12 | 5 | 7 |
|
||||
| 5 | 4 | 1 |
|
||||
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import scenario
|
||||
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def other_fixture(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@scenario("outline.feature", "Outlined given, when, thens", example_converters=dict(start=int, eat=float, left=str))
|
||||
def test_outlined_with_other_fixtures(other_fixture):
|
||||
"""Test outlined scenario also using other parametrized fixture."""
|
||||
@scenario(
|
||||
"outline.feature",
|
||||
"Outlined given, when, thens",
|
||||
example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_outline(other_fixture):
|
||||
pass
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=6)
|
||||
|
||||
|
||||
@scenario(
|
||||
"outline.feature", "Outlined with vertical example table", example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_vertical_example(request):
|
||||
def test_vertical_example(testdir):
|
||||
"""Test outlined scenario with vertical examples table."""
|
||||
assert get_parametrize_markers_args(request.node) == (["start", "eat", "left"], [[12, 5.0, "7"], [2, 1.0, "1"]])
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined with vertical example table
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples: Vertical
|
||||
| start | 12 | 2 |
|
||||
| eat | 5 | 1 |
|
||||
| left | 7 | 1 |
|
||||
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario(
|
||||
"outline.feature",
|
||||
"Outlined with vertical example table",
|
||||
example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_outline(request):
|
||||
assert get_parametrize_markers_args(request.node) == (
|
||||
["start", "eat", "left"],
|
||||
[
|
||||
[12, 5.0, "7"],
|
||||
[2, 1.0, "1"],
|
||||
],
|
||||
)
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
@given("there are <start> <fruits>")
|
||||
def start_fruits(start, fruits):
|
||||
assert isinstance(start, int)
|
||||
return {fruits: dict(start=start)}
|
||||
def test_outlined_feature(testdir):
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| 12 | 5 | 7 |
|
||||
| 5 | 4 | 1 |
|
||||
|
||||
@when("I eat <eat> <fruits>")
|
||||
def eat_fruits(start_fruits, eat, fruits):
|
||||
assert isinstance(eat, float)
|
||||
start_fruits[fruits]["eat"] = eat
|
||||
Scenario Outline: Outlined given, when, thens
|
||||
Given there are <start> <fruits>
|
||||
When I eat <eat> <fruits>
|
||||
Then I should have <left> <fruits>
|
||||
|
||||
Examples:
|
||||
| fruits |
|
||||
| oranges |
|
||||
| apples |
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
@then("I should have <left> <fruits>")
|
||||
def should_have_left_fruits(start_fruits, start, eat, left, fruits):
|
||||
assert isinstance(left, str)
|
||||
assert start - eat == int(left)
|
||||
assert start_fruits[fruits]["start"] == start
|
||||
assert start_fruits[fruits]["eat"] == eat
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import given, when, then, scenario
|
||||
|
||||
|
||||
@scenario(
|
||||
"outline_feature.feature", "Outlined given, when, thens", example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_outlined_feature(request):
|
||||
@scenario(
|
||||
"outline.feature",
|
||||
"Outlined given, when, thens",
|
||||
example_converters=dict(start=int, eat=float, left=str)
|
||||
)
|
||||
def test_outline(request):
|
||||
assert get_parametrize_markers_args(request.node) == (
|
||||
["start", "eat", "left"],
|
||||
[[12, 5.0, "7"], [5, 4.0, "1"]],
|
||||
|
@ -168,14 +344,38 @@ def test_outlined_feature(request):
|
|||
[["oranges"], ["apples"]],
|
||||
)
|
||||
|
||||
@given("there are <start> <fruits>")
|
||||
def start_fruits(start, fruits):
|
||||
assert isinstance(start, int)
|
||||
return {fruits: dict(start=start)}
|
||||
|
||||
|
||||
@when("I eat <eat> <fruits>")
|
||||
def eat_fruits(start_fruits, eat, fruits):
|
||||
assert isinstance(eat, float)
|
||||
start_fruits[fruits]["eat"] = eat
|
||||
|
||||
|
||||
@then("I should have <left> <fruits>")
|
||||
def should_have_left_fruits(start_fruits, start, eat, left, fruits):
|
||||
assert isinstance(left, str)
|
||||
assert start - eat == int(left)
|
||||
assert start_fruits[fruits]["start"] == start
|
||||
assert start_fruits[fruits]["eat"] == eat
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=4)
|
||||
|
||||
|
||||
def test_outline_with_escaped_pipes(testdir):
|
||||
"""Test parametrized feature example table with escaped pipe characters in input."""
|
||||
features = testdir.mkdir("features")
|
||||
feature = features.join("test.feature")
|
||||
feature.write_text(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
r"""\
|
||||
Feature: Outline With Special characters
|
||||
|
||||
Scenario Outline: Outline with escaped pipe character
|
||||
|
@ -193,20 +393,18 @@ def test_outline_with_escaped_pipes(testdir):
|
|||
| bork \\\| | Ym9yayAgICBcXHw= |
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
"""\
|
||||
import base64
|
||||
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
|
||||
|
||||
@scenario("features/test.feature", "Outline with escaped pipe character")
|
||||
@scenario("outline.feature", "Outline with escaped pipe character")
|
||||
def test_outline_with_escaped_pipe_character(request):
|
||||
pass
|
||||
|
||||
|
@ -219,8 +417,9 @@ def test_outline_with_escaped_pipes(testdir):
|
|||
@then("<string2> should be the base64 encoding of <string1>")
|
||||
def string2_should_be_base64_encoding_of_string1(string2, string1):
|
||||
assert string1.encode() == base64.b64decode(string2.encode())
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["* 7 passed *"])
|
||||
result.assert_outcomes(passed=7)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
"""Scenario Outline with empty example values tests."""
|
||||
from pytest_bdd import given, scenario, then, when
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
import textwrap
|
||||
|
||||
|
||||
STEPS = """\
|
||||
from pytest_bdd import given, when, then
|
||||
|
||||
|
||||
@given("there are <start> cucumbers")
|
||||
|
@ -17,12 +20,77 @@ def eat_cucumbers(eat):
|
|||
def should_have_left_cucumbers(left):
|
||||
pass
|
||||
|
||||
"""
|
||||
|
||||
@scenario("outline.feature", "Outlined with empty example values")
|
||||
def test_scenario_with_empty_example_values(request):
|
||||
|
||||
def test_scenario_with_empty_example_values(testdir):
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined with empty example values
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples:
|
||||
| start | eat | left |
|
||||
| # | | |
|
||||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario("outline.feature", "Outlined with empty example values")
|
||||
def test_outline(request):
|
||||
assert get_parametrize_markers_args(request.node) == ([u"start", u"eat", u"left"], [["#", "", ""]])
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
@scenario("outline.feature", "Outlined with empty example values vertical")
|
||||
def test_scenario_with_empty_example_values_vertical(request):
|
||||
|
||||
def test_scenario_with_empty_example_values_vertical(testdir):
|
||||
testdir.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
Feature: Outline
|
||||
Scenario Outline: Outlined with empty example values vertical
|
||||
Given there are <start> cucumbers
|
||||
When I eat <eat> cucumbers
|
||||
Then I should have <left> cucumbers
|
||||
|
||||
Examples: Vertical
|
||||
| start | # |
|
||||
| eat | |
|
||||
| left | |
|
||||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import get_parametrize_markers_args
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario("outline.feature", "Outlined with empty example values vertical")
|
||||
def test_outline(request):
|
||||
assert get_parametrize_markers_args(request.node) == ([u"start", u"eat", u"left"], [["#", "", ""]])
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
from pytest_bdd import given
|
||||
|
||||
|
||||
@given("I have the overriden fixture")
|
||||
def overridable():
|
||||
return "child"
|
|
@ -1,36 +0,0 @@
|
|||
"""Test givens declared in the parent conftest and plugin files.
|
||||
|
||||
Check the parent given steps are collected, override them locally.
|
||||
"""
|
||||
|
||||
from pytest_bdd import given
|
||||
from pytest_bdd.steps import get_step_fixture_name, GIVEN
|
||||
|
||||
|
||||
@given("I have locally overriden fixture")
|
||||
def overridable():
|
||||
return "local"
|
||||
|
||||
|
||||
@given("I have locally overriden parent fixture")
|
||||
def parent():
|
||||
return "local"
|
||||
|
||||
|
||||
def test_override(request, overridable):
|
||||
"""Test locally overriden fixture."""
|
||||
|
||||
# Test the fixture is also collected by the text name
|
||||
fixture = request.getfixturevalue(get_step_fixture_name("I have locally overriden fixture", GIVEN))
|
||||
assert fixture(request) == "local"
|
||||
|
||||
# 'I have the overriden fixture' stands for overridable and is overriden locally
|
||||
fixture = request.getfixturevalue(get_step_fixture_name("I have the overriden fixture", GIVEN))
|
||||
assert fixture(request) == "local"
|
||||
|
||||
assert overridable == "local"
|
||||
|
||||
|
||||
def test_parent(parent):
|
||||
"""Test locally overriden parent fixture."""
|
||||
assert parent == "local"
|
|
@ -1,14 +0,0 @@
|
|||
"""Test givens declared in the parent conftest and plugin files.
|
||||
|
||||
Check the parent givens are collected and overriden in the local conftest.
|
||||
"""
|
||||
|
||||
|
||||
def test_parent(parent):
|
||||
"""Test parent given is collected."""
|
||||
assert parent == "parent"
|
||||
|
||||
|
||||
def test_override(overridable):
|
||||
"""Test the child conftest overriding the fixture."""
|
||||
assert overridable == "child"
|
|
@ -1,11 +0,0 @@
|
|||
from pytest_bdd import given
|
||||
|
||||
|
||||
@given("I have parent fixture")
|
||||
def parent():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have overridable parent fixture")
|
||||
def overridable():
|
||||
return "parent"
|
|
@ -2,18 +2,190 @@
|
|||
|
||||
Check the parent givens are collected and overriden in the local conftest.
|
||||
"""
|
||||
from pytest_bdd.steps import get_step_fixture_name, WHEN
|
||||
import textwrap
|
||||
|
||||
|
||||
def test_parent(parent, overridable):
|
||||
def test_parent(testdir):
|
||||
"""Test parent given is collected.
|
||||
|
||||
Both fixtures come from the parent conftest.
|
||||
"""
|
||||
testdir.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
||||
|
||||
@given("I have parent fixture")
|
||||
def parent():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have overridable parent fixture")
|
||||
def overridable():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
def test_parent(parent, overridable):
|
||||
assert parent == "parent"
|
||||
assert overridable == "parent"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
def test_global_when_step(request):
|
||||
|
||||
def test_global_when_step(testdir, request):
|
||||
"""Test when step defined in the parent conftest."""
|
||||
request.getfixturevalue(get_step_fixture_name("I use a when step from the parent conftest", WHEN))
|
||||
|
||||
testdir.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import when
|
||||
|
||||
|
||||
@when("I use a when step from the parent conftest")
|
||||
def global_when():
|
||||
pass
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
|
||||
subdir.join("test_library.py").write(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.steps import get_step_fixture_name, WHEN
|
||||
|
||||
def test_global_when_step(request):
|
||||
assert request.getfixturevalue(
|
||||
get_step_fixture_name("I use a when step from the parent conftest",
|
||||
WHEN,
|
||||
)
|
||||
)
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_child(testdir):
|
||||
"""Test the child conftest overriding the fixture."""
|
||||
testdir.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
||||
|
||||
@given("I have parent fixture")
|
||||
def parent():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have overridable parent fixture")
|
||||
def overridable():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
|
||||
subdir.join("conftest.py").write(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
||||
@given("I have overridable parent fixture")
|
||||
def overridable():
|
||||
return "child"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
subdir.join("test_library.py").write(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
def test_override(parent, overridable):
|
||||
assert parent == "parent"
|
||||
assert overridable == "child"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_local(testdir):
|
||||
"""Test locally overridden fixtures."""
|
||||
testdir.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
||||
|
||||
@given("I have parent fixture")
|
||||
def parent():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have overridable parent fixture")
|
||||
def overridable():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
|
||||
subdir.join("test_library.py").write(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
from pytest_bdd.steps import get_step_fixture_name, GIVEN
|
||||
|
||||
|
||||
@given("I have locally overriden fixture")
|
||||
def overridable():
|
||||
return "local"
|
||||
|
||||
|
||||
@given("I have locally overriden parent fixture")
|
||||
def parent():
|
||||
return "local"
|
||||
|
||||
|
||||
def test_local(request, parent, overridable):
|
||||
assert parent == "local"
|
||||
assert overridable == "local"
|
||||
|
||||
fixture = request.getfixturevalue(
|
||||
get_step_fixture_name("I have locally overriden fixture", GIVEN)
|
||||
)
|
||||
assert fixture(request) == "local"
|
||||
|
||||
fixture = request.getfixturevalue(
|
||||
get_step_fixture_name("I have locally overriden parent fixture", GIVEN)
|
||||
)
|
||||
assert fixture(request) == "local"
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
"""Given tests."""
|
||||
import pytest
|
||||
import textwrap
|
||||
|
||||
from pytest_bdd import given, then, scenario
|
||||
from pytest_bdd.steps import StepError
|
||||
|
||||
|
||||
def test_root_alias(testdir):
|
||||
testdir.makefile(
|
||||
|
|
Loading…
Reference in New Issue