Use `_` as step function name. It should not matter what the name is.
Inspired by the `ward` testing framework
This commit is contained in:
parent
f4a7bdfaf1
commit
478e21bcdf
|
@ -31,7 +31,7 @@ def pytest_addhooks(pluginmanager: PytestPluginManager) -> None:
|
|||
@given("trace")
|
||||
@when("trace")
|
||||
@then("trace")
|
||||
def trace() -> None:
|
||||
def _() -> None:
|
||||
"""Enter pytest's pdb trace."""
|
||||
pytest.set_trace()
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
Example:
|
||||
|
||||
@given("I have an article", target_fixture="article")
|
||||
def given_article(author):
|
||||
def _(author):
|
||||
return create_test_article(author=author)
|
||||
|
||||
|
||||
@when("I go to the article page")
|
||||
def go_to_the_article_page(browser, article):
|
||||
def _(browser, article):
|
||||
browser.visit(urljoin(browser.url, "/articles/{0}/".format(article.id)))
|
||||
|
||||
|
||||
@then("I should not see the error message")
|
||||
def no_error_message(browser):
|
||||
def _(browser):
|
||||
with pytest.raises(ElementDoesNotExist):
|
||||
browser.find_by_css(".message.error").first
|
||||
|
||||
|
@ -22,7 +22,7 @@ Multiple names for the steps:
|
|||
|
||||
@given("I have an article")
|
||||
@given("there is an article")
|
||||
def article(author):
|
||||
def _(author):
|
||||
return create_test_article(author=author)
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ Reusing existing fixtures for a different step name:
|
|||
|
||||
|
||||
@given("I have a beautiful article")
|
||||
def given_beautiful_article(article):
|
||||
def _(article):
|
||||
pass
|
||||
|
||||
"""
|
||||
|
|
|
@ -19,7 +19,7 @@ def test_${ make_python_name(scenario.name)}():
|
|||
% endfor
|
||||
% for step in steps:
|
||||
@${step.type}(${ make_string_literal(step.name)})
|
||||
def ${ make_python_name(step.name)}():
|
||||
def _():
|
||||
${make_python_docstring(step.name)}
|
||||
raise NotImplementedError
|
||||
% if not loop.last:
|
||||
|
|
|
@ -37,17 +37,17 @@ def test_every_step_takes_param_with_the_same_name(testdir):
|
|||
|
||||
|
||||
@given(parsers.cfparse("I have {euro:d} Euro"))
|
||||
def i_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@when(parsers.cfparse("I pay {euro:d} Euro"))
|
||||
def i_pay(euro, values, request):
|
||||
def _(euro, values, request):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@then(parsers.cfparse("I should have {euro:d} Euro"))
|
||||
def i_should_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
"""
|
||||
|
@ -89,17 +89,17 @@ def test_argument_in_when(testdir):
|
|||
|
||||
|
||||
@given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
|
||||
def argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@when(parsers.cfparse("I get argument {arg:d}"))
|
||||
def get_argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@then(parsers.cfparse("My argument should be {arg:d}"))
|
||||
def assert_that_my_argument_is_arg(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
assert arguments["arg"] == arg
|
||||
|
||||
"""
|
||||
|
|
|
@ -36,17 +36,17 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse("I have {euro:d} Euro"))
|
||||
def i_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@when(parsers.parse("I pay {euro:d} Euro"))
|
||||
def i_pay(euro, values, request):
|
||||
def _(euro, values, request):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@then(parsers.parse("I should have {euro:d} Euro"))
|
||||
def i_should_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
"""
|
||||
|
@ -87,17 +87,17 @@ def test_argument_in_when_step_1(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
|
||||
def argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@when(parsers.parse("I get argument {arg:d}"))
|
||||
def get_argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@then(parsers.parse("My argument should be {arg:d}"))
|
||||
def assert_that_my_argument_is_arg(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
assert arguments["arg"] == arg
|
||||
|
||||
"""
|
||||
|
|
|
@ -35,17 +35,17 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
return [1, 2, 1, 0, 999999]
|
||||
|
||||
@given(parsers.re(r"I have (?P<euro>\d+) Euro"), converters=dict(euro=int))
|
||||
def i_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@when(parsers.re(r"I pay (?P<euro>\d+) Euro"), converters=dict(euro=int))
|
||||
def i_pay(euro, values, request):
|
||||
def _(euro, values, request):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@then(parsers.re(r"I should have (?P<euro>\d+) Euro"), converters=dict(euro=int))
|
||||
def i_should_have(euro, values):
|
||||
def _(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
"""
|
||||
|
@ -86,17 +86,17 @@ def test_argument_in_when(testdir):
|
|||
pass
|
||||
|
||||
@given(parsers.re(r"I have an argument (?P<arg>\d+)"))
|
||||
def argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@when(parsers.re(r"I get argument (?P<arg>\d+)"))
|
||||
def get_argument(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
arguments["arg"] = arg
|
||||
|
||||
|
||||
@then(parsers.re(r"My argument should be (?P<arg>\d+)"))
|
||||
def assert_that_my_argument_is_arg(arguments, arg):
|
||||
def _(arguments, arg):
|
||||
assert arguments["arg"] == arg
|
||||
|
||||
"""
|
||||
|
|
|
@ -34,24 +34,24 @@ def test_step_alias(testdir):
|
|||
|
||||
|
||||
@given("I have an empty list", target_fixture="results")
|
||||
def results():
|
||||
def _():
|
||||
return []
|
||||
|
||||
|
||||
@given("I have foo (which is 1) in my list")
|
||||
@given("I have bar (alias of foo) in my list")
|
||||
def foo(results):
|
||||
def _(results):
|
||||
results.append(1)
|
||||
|
||||
|
||||
@when("I do crash (which is 2)")
|
||||
@when("I do boom (alias of crash)")
|
||||
def crash(results):
|
||||
def _(results):
|
||||
results.append(2)
|
||||
|
||||
|
||||
@then("my list should be [1, 1, 2, 2]")
|
||||
def check_results(results):
|
||||
def _(results):
|
||||
assert results == [1, 1, 2, 2]
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -34,40 +34,40 @@ def foo():
|
|||
|
||||
|
||||
@given(parsers.re(r"a background step with multiple lines:\n(?P<data>.+)", flags=re.DOTALL))
|
||||
def multi_line(foo, data):
|
||||
def _(foo, data):
|
||||
assert data == "one\ntwo"
|
||||
|
||||
|
||||
@given('foo has a value "bar"')
|
||||
def bar(foo):
|
||||
def _(foo):
|
||||
foo["bar"] = "bar"
|
||||
return foo["bar"]
|
||||
|
||||
|
||||
@given('foo has a value "dummy"')
|
||||
def dummy(foo):
|
||||
def _(foo):
|
||||
foo["dummy"] = "dummy"
|
||||
return foo["dummy"]
|
||||
|
||||
|
||||
@given('foo has no value "bar"')
|
||||
def no_bar(foo):
|
||||
def _(foo):
|
||||
assert foo["bar"]
|
||||
del foo["bar"]
|
||||
|
||||
|
||||
@then('foo should have value "bar"')
|
||||
def foo_has_bar(foo):
|
||||
def _(foo):
|
||||
assert foo["bar"] == "bar"
|
||||
|
||||
|
||||
@then('foo should have value "dummy"')
|
||||
def foo_has_dummy(foo):
|
||||
def _(foo):
|
||||
assert foo["dummy"] == "dummy"
|
||||
|
||||
|
||||
@then('foo should not have value "bar"')
|
||||
def foo_has_no_bar(foo):
|
||||
def _(foo):
|
||||
assert "bar" not in foo
|
||||
|
||||
"""
|
||||
|
|
|
@ -80,19 +80,19 @@ def test_step_trace(testdir):
|
|||
from pytest_bdd import given, when, scenario, parsers
|
||||
|
||||
@given('a passing step')
|
||||
def a_passing_step():
|
||||
def _():
|
||||
return 'pass'
|
||||
|
||||
@given('some other passing step')
|
||||
def some_other_passing_step():
|
||||
def _():
|
||||
return 'pass'
|
||||
|
||||
@given('a failing step')
|
||||
def a_failing_step():
|
||||
def _():
|
||||
raise Exception('Error')
|
||||
|
||||
@given(parsers.parse('type {type} and value {value}'))
|
||||
def type_type_and_value_value():
|
||||
def _():
|
||||
return 'pass'
|
||||
|
||||
@scenario('test.feature', 'Passing')
|
||||
|
|
|
@ -36,7 +36,7 @@ def test_description(testdir):
|
|||
|
||||
|
||||
@given("I have a bar")
|
||||
def bar():
|
||||
def _():
|
||||
return "bar"
|
||||
|
||||
def test_scenario_description():
|
||||
|
|
|
@ -17,16 +17,16 @@ from pytest_bdd import given, when, then, scenario
|
|||
|
||||
|
||||
@given('there is a bar')
|
||||
def a_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@when('the bar is accessed')
|
||||
def the_bar_is_accessed():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then('world explodes')
|
||||
def world_explodes():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
|
@ -123,16 +123,16 @@ def test_error_message_should_be_displayed(testdir, verbosity):
|
|||
|
||||
|
||||
@given('there is a bar')
|
||||
def a_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@when('the bar is accessed')
|
||||
def the_bar_is_accessed():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then('world explodes')
|
||||
def world_explodes():
|
||||
def _():
|
||||
raise Exception("BIGBADABOOM")
|
||||
|
||||
|
||||
|
@ -157,16 +157,16 @@ def test_local_variables_should_be_displayed_when_showlocals_option_is_used(test
|
|||
|
||||
|
||||
@given('there is a bar')
|
||||
def a_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@when('the bar is accessed')
|
||||
def the_bar_is_accessed():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then('world explodes')
|
||||
def world_explodes():
|
||||
def _():
|
||||
local_var = "MULTIPASS"
|
||||
raise Exception("BIGBADABOOM")
|
||||
|
||||
|
@ -209,15 +209,15 @@ def test_step_parameters_should_be_replaced_by_their_values(testdir):
|
|||
from pytest_bdd import given, when, scenario, then, parsers
|
||||
|
||||
@given(parsers.parse('there are {start} cucumbers'), target_fixture="start_cucumbers")
|
||||
def start_cucumbers(start):
|
||||
def _(start):
|
||||
return start
|
||||
|
||||
@when(parsers.parse('I eat {eat} cucumbers'))
|
||||
def eat_cucumbers(start_cucumbers, eat):
|
||||
def _(start_cucumbers, eat):
|
||||
pass
|
||||
|
||||
@then(parsers.parse('I should have {left} cucumbers'))
|
||||
def should_have_left_cucumbers(start_cucumbers, left):
|
||||
def _(start_cucumbers, left):
|
||||
pass
|
||||
|
||||
@scenario('test.feature', 'Scenario example 2')
|
||||
|
|
|
@ -88,12 +88,12 @@ def test_multiline(testdir, feature_text, expected_text):
|
|||
|
||||
|
||||
@given(parsers.parse("I have a step with:\\n{{text}}"), target_fixture="text")
|
||||
def i_have_text(text):
|
||||
def _(text):
|
||||
return text
|
||||
|
||||
|
||||
@then("the text should be parsed with correct indentation")
|
||||
def text_should_be_correct(text):
|
||||
def _(text):
|
||||
assert text == expected_text
|
||||
|
||||
""".format(
|
||||
|
@ -138,12 +138,12 @@ def test_multiline_wrong_indent(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse("I have a step with:\\n{{text}}"), target_fixture="text")
|
||||
def i_have_text(text):
|
||||
def _(text):
|
||||
return text
|
||||
|
||||
|
||||
@then("the text should be parsed with correct indentation")
|
||||
def text_should_be_correct(text):
|
||||
def _(text):
|
||||
assert text == expected_text
|
||||
|
||||
"""
|
||||
|
|
|
@ -22,18 +22,18 @@ def test_background_no_strict_gherkin(testdir):
|
|||
return {}
|
||||
|
||||
@when('foo has a value "bar"')
|
||||
def bar(foo):
|
||||
def _(foo):
|
||||
foo["bar"] = "bar"
|
||||
return foo["bar"]
|
||||
|
||||
|
||||
@when('foo is not boolean')
|
||||
def not_boolean(foo):
|
||||
def _(foo):
|
||||
assert foo is not bool
|
||||
|
||||
|
||||
@when('foo has not a value "baz"')
|
||||
def has_not_baz(foo):
|
||||
def _(foo):
|
||||
assert "baz" not in foo
|
||||
"""
|
||||
)
|
||||
|
@ -78,18 +78,18 @@ def test_scenario_no_strict_gherkin(testdir):
|
|||
return {}
|
||||
|
||||
@when('foo has a value "bar"')
|
||||
def bar(foo):
|
||||
def _(foo):
|
||||
foo["bar"] = "bar"
|
||||
return foo["bar"]
|
||||
|
||||
|
||||
@when('foo is not boolean')
|
||||
def not_boolean(foo):
|
||||
def _(foo):
|
||||
assert foo is not bool
|
||||
|
||||
|
||||
@when('foo has not a value "baz"')
|
||||
def has_not_baz(foo):
|
||||
def _(foo):
|
||||
assert "baz" not in foo
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -10,21 +10,21 @@ from pytest_bdd.utils import dump_obj
|
|||
|
||||
|
||||
@given(parsers.parse("there are {start:d} cucumbers"), target_fixture="cucumbers")
|
||||
def given_cucumbers(start):
|
||||
def _(start):
|
||||
assert isinstance(start, int)
|
||||
dump_obj(start)
|
||||
return {"start": start}
|
||||
|
||||
|
||||
@when(parsers.parse("I eat {eat:g} cucumbers"))
|
||||
def eat_cucumbers(cucumbers, eat):
|
||||
def _(cucumbers, eat):
|
||||
assert isinstance(eat, float)
|
||||
dump_obj(eat)
|
||||
cucumbers["eat"] = eat
|
||||
|
||||
|
||||
@then(parsers.parse("I should have {left} cucumbers"))
|
||||
def should_have_left_cucumbers(cucumbers, left):
|
||||
def _(cucumbers, left):
|
||||
assert isinstance(left, str)
|
||||
dump_obj(left)
|
||||
assert cucumbers["start"] - cucumbers["eat"] == int(left)
|
||||
|
@ -204,7 +204,7 @@ def test_outline_with_escaped_pipes(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse("I print the {string}"))
|
||||
def i_print_the_string(string):
|
||||
def _(string):
|
||||
dump_obj(string)
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -10,17 +10,17 @@ from pytest_bdd.utils import dump_obj
|
|||
# Using `parsers.re` so that we can match empty values
|
||||
|
||||
@given(parsers.re("there are (?P<start>.*?) cucumbers"))
|
||||
def start_cucumbers(start):
|
||||
def _(start):
|
||||
dump_obj(start)
|
||||
|
||||
|
||||
@when(parsers.re("I eat (?P<eat>.*?) cucumbers"))
|
||||
def eat_cucumbers(eat):
|
||||
def _(eat):
|
||||
dump_obj(eat)
|
||||
|
||||
|
||||
@then(parsers.re("I should have (?P<left>.*?) cucumbers"))
|
||||
def should_have_left_cucumbers(left):
|
||||
def _(left):
|
||||
dump_obj(left)
|
||||
|
||||
"""
|
||||
|
|
|
@ -65,31 +65,31 @@ def test_step_trace(testdir):
|
|||
from pytest_bdd import given, when, then, scenarios, parsers
|
||||
|
||||
@given('a passing step')
|
||||
def a_passing_step():
|
||||
def _():
|
||||
return 'pass'
|
||||
|
||||
@given('some other passing step')
|
||||
def some_other_passing_step():
|
||||
def _():
|
||||
return 'pass'
|
||||
|
||||
@given('a failing step')
|
||||
def a_failing_step():
|
||||
def _():
|
||||
raise Exception('Error')
|
||||
|
||||
@given(parsers.parse('there are {start:d} cucumbers'), target_fixture="cucumbers")
|
||||
def given_cucumbers(start):
|
||||
def _(start):
|
||||
assert isinstance(start, int)
|
||||
return {"start": start}
|
||||
|
||||
|
||||
@when(parsers.parse('I eat {eat:g} cucumbers'))
|
||||
def eat_cucumbers(cucumbers, eat):
|
||||
def _(cucumbers, eat):
|
||||
assert isinstance(eat, float)
|
||||
cucumbers['eat'] = eat
|
||||
|
||||
|
||||
@then(parsers.parse('I should have {left} cucumbers'))
|
||||
def should_have_left_cucumbers(cucumbers, left):
|
||||
def _(cucumbers, left):
|
||||
assert isinstance(left, str)
|
||||
assert cucumbers['start'] - cucumbers['eat'] == int(left)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ def test_when_function_name_same_as_step_name(testdir):
|
|||
pass
|
||||
|
||||
@when("something")
|
||||
def something():
|
||||
def _():
|
||||
return "something"
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -73,17 +73,17 @@ def test_scenario_comments(testdir):
|
|||
|
||||
|
||||
@given("I have a bar")
|
||||
def bar():
|
||||
def _():
|
||||
return "bar"
|
||||
|
||||
|
||||
@given("comments should be at the start of words")
|
||||
def comments():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then(parsers.parse("this is not {acomment}"))
|
||||
def a_comment(acomment):
|
||||
def _(acomment):
|
||||
assert re.search("a.*comment", acomment)
|
||||
|
||||
"""
|
||||
|
@ -138,11 +138,11 @@ def test_simple(testdir, pytest_params):
|
|||
pass
|
||||
|
||||
@given("I have a bar")
|
||||
def bar():
|
||||
def _():
|
||||
return "bar"
|
||||
|
||||
@then("pass")
|
||||
def bar():
|
||||
def _():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
@ -180,15 +180,15 @@ def test_angular_brakets_are_not_parsed(testdir):
|
|||
scenarios("simple.feature")
|
||||
|
||||
@given("I have a <tag>")
|
||||
def bar():
|
||||
def _():
|
||||
return "tag"
|
||||
|
||||
@given(parsers.parse("I have a templated {foo}"))
|
||||
def bar(foo):
|
||||
def _(foo):
|
||||
return "foo"
|
||||
|
||||
@then("pass")
|
||||
def bar():
|
||||
def _():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@ def test_scenarios(testdir, pytest_params):
|
|||
from pytest_bdd import given
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
print('bar!')
|
||||
return 'bar'
|
||||
"""
|
||||
|
|
|
@ -32,37 +32,37 @@ def test_steps(testdir):
|
|||
pass
|
||||
|
||||
@given('I have a foo fixture with value "foo"', target_fixture="foo")
|
||||
def foo():
|
||||
def _():
|
||||
return "foo"
|
||||
|
||||
|
||||
@given("there is a list", target_fixture="results")
|
||||
def results():
|
||||
def _():
|
||||
return []
|
||||
|
||||
|
||||
@when("I append 1 to the list")
|
||||
def append_1(results):
|
||||
def _(results):
|
||||
results.append(1)
|
||||
|
||||
|
||||
@when("I append 2 to the list")
|
||||
def append_2(results):
|
||||
def _(results):
|
||||
results.append(2)
|
||||
|
||||
|
||||
@when("I append 3 to the list")
|
||||
def append_3(results):
|
||||
def _(results):
|
||||
results.append(3)
|
||||
|
||||
|
||||
@then('foo should have value "foo"')
|
||||
def foo_is_foo(foo):
|
||||
def _(foo):
|
||||
assert foo == "foo"
|
||||
|
||||
|
||||
@then("the list should be [1, 2, 3]")
|
||||
def check_results(results):
|
||||
def _(results):
|
||||
assert results == [1, 2, 3]
|
||||
|
||||
"""
|
||||
|
@ -102,19 +102,19 @@ def test_step_function_can_be_decorated_multiple_times(testdir):
|
|||
|
||||
@given(parsers.parse("there is a foo with value {value}"), target_fixture="foo")
|
||||
@given(parsers.parse("there is a second foo with value {value}"), target_fixture="second_foo")
|
||||
def foo(value):
|
||||
def _(value):
|
||||
return value
|
||||
|
||||
|
||||
@when("I do nothing")
|
||||
@when("I do nothing again")
|
||||
def do_nothing():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then("I make no mistakes")
|
||||
@then("I make no mistakes again")
|
||||
def no_errors():
|
||||
def _():
|
||||
assert True
|
||||
|
||||
"""
|
||||
|
@ -152,22 +152,22 @@ def test_all_steps_can_provide_fixtures(testdir):
|
|||
scenarios("steps.feature")
|
||||
|
||||
@given(parsers.parse('Foo is "{value}"'), target_fixture="foo")
|
||||
def given_foo_is_value(value):
|
||||
def _(value):
|
||||
return value
|
||||
|
||||
|
||||
@when(parsers.parse('Foo is "{value}"'), target_fixture="foo")
|
||||
def when_foo_is_value(value):
|
||||
def _(value):
|
||||
return value
|
||||
|
||||
|
||||
@then(parsers.parse('Foo is "{value}"'), target_fixture="foo")
|
||||
def then_foo_is_value(value):
|
||||
def _(value):
|
||||
return value
|
||||
|
||||
|
||||
@then(parsers.parse('foo should be "{value}"'))
|
||||
def foo_is_foo(foo, value):
|
||||
def _(foo, value):
|
||||
assert foo == value
|
||||
|
||||
"""
|
||||
|
@ -202,12 +202,12 @@ def test_when_first(testdir):
|
|||
pass
|
||||
|
||||
@when("I do nothing")
|
||||
def do_nothing():
|
||||
def _():
|
||||
pass
|
||||
|
||||
|
||||
@then("I make no mistakes")
|
||||
def no_errors():
|
||||
def _():
|
||||
assert True
|
||||
|
||||
"""
|
||||
|
@ -243,11 +243,11 @@ def test_then_after_given(testdir):
|
|||
pass
|
||||
|
||||
@given('I have a foo fixture with value "foo"', target_fixture="foo")
|
||||
def foo():
|
||||
def _():
|
||||
return "foo"
|
||||
|
||||
@then('foo should have value "foo"')
|
||||
def foo_is_foo(foo):
|
||||
def _(foo):
|
||||
assert foo == "foo"
|
||||
|
||||
"""
|
||||
|
@ -280,12 +280,12 @@ def test_conftest(testdir):
|
|||
|
||||
|
||||
@given("I have a bar", target_fixture="bar")
|
||||
def bar():
|
||||
def _():
|
||||
return "bar"
|
||||
|
||||
|
||||
@then('bar should have value "bar"')
|
||||
def bar_is_bar(bar):
|
||||
def _(bar):
|
||||
assert bar == "bar"
|
||||
|
||||
"""
|
||||
|
@ -329,12 +329,12 @@ def test_multiple_given(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse("foo is {value}"), target_fixture="foo")
|
||||
def foo(value):
|
||||
def _(value):
|
||||
return value
|
||||
|
||||
|
||||
@then(parsers.parse("foo should be {value}"))
|
||||
def foo_should_be(foo, value):
|
||||
def _(foo, value):
|
||||
assert foo == value
|
||||
|
||||
|
||||
|
@ -376,15 +376,15 @@ def test_step_hooks(testdir):
|
|||
from pytest_bdd import given, when, scenario
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@when('it fails')
|
||||
def when_it_fails():
|
||||
def _():
|
||||
raise Exception('when fails')
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -392,7 +392,7 @@ def test_step_hooks(testdir):
|
|||
raise Exception('dependency fails')
|
||||
|
||||
@when("it's dependency fails")
|
||||
def when_dependency_fails(dependency):
|
||||
def _(dependency):
|
||||
pass
|
||||
|
||||
@scenario('test.feature', "When step's dependency a has failure")
|
||||
|
@ -408,7 +408,7 @@ def test_step_hooks(testdir):
|
|||
pass
|
||||
|
||||
@when('foo')
|
||||
def foo():
|
||||
def _():
|
||||
return 'foo'
|
||||
|
||||
@scenario('test.feature', 'When step validation error happens')
|
||||
|
@ -489,11 +489,11 @@ def test_step_trace(testdir):
|
|||
from pytest_bdd import given, when, scenario
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@when('it fails')
|
||||
def when_it_fails():
|
||||
def _():
|
||||
raise Exception('when fails')
|
||||
|
||||
@scenario('test.feature', 'When step has failure')
|
||||
|
@ -509,7 +509,7 @@ def test_step_trace(testdir):
|
|||
pass
|
||||
|
||||
@when('foo')
|
||||
def foo():
|
||||
def _():
|
||||
return 'foo'
|
||||
|
||||
@scenario('test.feature', 'When step validation error happens')
|
||||
|
@ -561,14 +561,14 @@ Feature: A feature
|
|||
scenarios("a.feature")
|
||||
|
||||
@when("I setup stuff", target_fixture="stuff")
|
||||
def stuff():
|
||||
def _():
|
||||
print("Setting up...")
|
||||
yield 42
|
||||
print("Tearing down...")
|
||||
|
||||
|
||||
@then("stuff should be 42")
|
||||
def check_stuff(stuff):
|
||||
def _(stuff):
|
||||
assert stuff == 42
|
||||
print("Asserted stuff is 42")
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ def test_tags_selector(testdir):
|
|||
from pytest_bdd import given, scenarios
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
scenarios('test.feature')
|
||||
|
@ -101,11 +101,11 @@ def test_tags_after_background_issue_160(testdir):
|
|||
from pytest_bdd import given, scenarios
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
@given('I have a baz')
|
||||
def i_have_baz():
|
||||
def _():
|
||||
return 'baz'
|
||||
|
||||
scenarios('test.feature')
|
||||
|
@ -151,7 +151,7 @@ def test_apply_tag_hook(testdir):
|
|||
from pytest_bdd import given, scenarios
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
scenarios('test.feature')
|
||||
|
@ -197,7 +197,7 @@ def test_tag_with_spaces(testdir):
|
|||
from pytest_bdd import given, scenarios
|
||||
|
||||
@given('I have a bar')
|
||||
def i_have_bar():
|
||||
def _():
|
||||
return 'bar'
|
||||
|
||||
scenarios('test.feature')
|
||||
|
@ -225,11 +225,11 @@ def test_at_in_scenario(testdir):
|
|||
from pytest_bdd import given, scenarios
|
||||
|
||||
@given('I have a foo@bar')
|
||||
def i_have_at():
|
||||
def _():
|
||||
return 'foo@bar'
|
||||
|
||||
@given('I have a baz')
|
||||
def i_have_baz():
|
||||
def _():
|
||||
return 'baz'
|
||||
|
||||
scenarios('test.feature')
|
||||
|
|
|
@ -50,7 +50,7 @@ def test_generate_missing(testdir):
|
|||
scenario = functools.partial(scenario, "generation.feature")
|
||||
|
||||
@given("I have a bar")
|
||||
def i_have_a_bar():
|
||||
def _():
|
||||
return "bar"
|
||||
|
||||
@scenario("Scenario tests which are already bound to the tests stay as is")
|
||||
|
@ -114,19 +114,19 @@ def test_generate_missing_with_step_parsers(testdir):
|
|||
scenarios("generation.feature")
|
||||
|
||||
@given("I use the string parser without parameter")
|
||||
def i_have_a_bar():
|
||||
def _():
|
||||
return None
|
||||
|
||||
@given(parsers.parse("I use parsers.parse with parameter {param}"))
|
||||
def i_have_n_baz(param):
|
||||
def _(param):
|
||||
return param
|
||||
|
||||
@given(parsers.re(r"^I use parsers.re with parameter (?P<param>.*?)$"))
|
||||
def i_have_n_baz(param):
|
||||
def _(param):
|
||||
return param
|
||||
|
||||
@given(parsers.cfparse("I use parsers.cfparse with parameter {param:d}"))
|
||||
def i_have_n_baz(param):
|
||||
def _(param):
|
||||
return param
|
||||
"""
|
||||
)
|
||||
|
|
|
@ -31,12 +31,12 @@ def test_parent(testdir):
|
|||
|
||||
|
||||
@given("I have a parent fixture", target_fixture="parent")
|
||||
def parent():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have an overridable fixture", target_fixture="overridable")
|
||||
def overridable():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
|
@ -113,12 +113,12 @@ def test_child(testdir):
|
|||
|
||||
|
||||
@given("I have a parent fixture", target_fixture="parent")
|
||||
def parent():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have an overridable fixture", target_fixture="overridable")
|
||||
def overridable():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
|
@ -133,7 +133,7 @@ def test_child(testdir):
|
|||
from pytest_bdd import given
|
||||
|
||||
@given("I have an overridable fixture", target_fixture="overridable")
|
||||
def overridable():
|
||||
def _():
|
||||
return "child"
|
||||
|
||||
"""
|
||||
|
@ -178,12 +178,12 @@ def test_local(testdir):
|
|||
|
||||
|
||||
@given("I have a parent fixture", target_fixture="parent")
|
||||
def parent():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
|
||||
@given("I have an overridable fixture", target_fixture="overridable")
|
||||
def overridable():
|
||||
def _():
|
||||
return "parent"
|
||||
|
||||
"""
|
||||
|
@ -210,12 +210,12 @@ def test_local(testdir):
|
|||
|
||||
|
||||
@given("I have an overridable fixture", target_fixture="overridable")
|
||||
def overridable():
|
||||
def _():
|
||||
return "local"
|
||||
|
||||
|
||||
@given("I have a parent fixture", target_fixture="parent")
|
||||
def parent():
|
||||
def _():
|
||||
return "local"
|
||||
|
||||
|
||||
|
|
|
@ -53,25 +53,25 @@ def test_generate(testdir, monkeypatch, capsys):
|
|||
|
||||
|
||||
@given('1 have a fixture (appends 1 to a list) in reuse syntax')
|
||||
def have_a_fixture_appends_1_to_a_list_in_reuse_syntax():
|
||||
def _():
|
||||
"""1 have a fixture (appends 1 to a list) in reuse syntax."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@given('I have an empty list')
|
||||
def i_have_an_empty_list():
|
||||
def _():
|
||||
"""I have an empty list."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@when('I use this fixture')
|
||||
def i_use_this_fixture():
|
||||
def _():
|
||||
"""I use this fixture."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@then('my list should be [1]')
|
||||
def my_list_should_be_1():
|
||||
def _():
|
||||
"""my list should be [1]."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -119,37 +119,37 @@ def test_generate_with_quotes(testdir):
|
|||
|
||||
|
||||
@given('I have a fixture with "double" quotes')
|
||||
def i_have_a_fixture_with_double_quotes():
|
||||
def _():
|
||||
"""I have a fixture with "double" quotes."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@given('I have a fixture with \\'single\\' quotes')
|
||||
def i_have_a_fixture_with_single_quotes():
|
||||
def _():
|
||||
"""I have a fixture with 'single' quotes."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@given('I have a fixture with double-quote """triple""" quotes')
|
||||
def i_have_a_fixture_with_doublequote_triple_quotes():
|
||||
def _():
|
||||
"""I have a fixture with double-quote \\"\\"\\"triple\\"\\"\\" quotes."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@given('I have a fixture with single-quote \\'\\'\\'triple\\'\\'\\' quotes')
|
||||
def i_have_a_fixture_with_singlequote_triple_quotes():
|
||||
def _():
|
||||
"""I have a fixture with single-quote \'\'\'triple\'\'\' quotes."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@when('I generate the code')
|
||||
def i_generate_the_code():
|
||||
def _():
|
||||
"""I generate the code."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@then('The generated string should be written')
|
||||
def the_generated_string_should_be_written():
|
||||
def _():
|
||||
"""The generated string should be written."""
|
||||
raise NotImplementedError
|
||||
'''
|
||||
|
@ -195,19 +195,19 @@ def test_unicode_characters(testdir, monkeypatch):
|
|||
|
||||
|
||||
@given('We have a circle')
|
||||
def we_have_a_circle():
|
||||
def _():
|
||||
"""We have a circle."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@when('We want to know its circumference')
|
||||
def we_want_to_know_its_circumference():
|
||||
def _():
|
||||
"""We want to know its circumference."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@then('We calculate 2 * ℼ * 𝑟')
|
||||
def we_calculate_2__ℼ__𝑟():
|
||||
def _():
|
||||
"""We calculate 2 * ℼ * 𝑟."""
|
||||
raise NotImplementedError
|
||||
'''
|
||||
|
|
|
@ -25,12 +25,12 @@ def test_given_injection(testdir):
|
|||
pass
|
||||
|
||||
@given("I have injecting given", target_fixture="foo")
|
||||
def injecting_given():
|
||||
def _():
|
||||
return "injected foo"
|
||||
|
||||
|
||||
@then('foo should be "injected foo"')
|
||||
def foo_is_injected_foo(foo):
|
||||
def _(foo):
|
||||
assert foo == "injected foo"
|
||||
|
||||
"""
|
||||
|
|
|
@ -38,7 +38,7 @@ def test_steps_in_feature_file_have_unicode(testdir):
|
|||
|
||||
|
||||
@given(parsers.parse(u"у мене є рядок який містить '{content}'"))
|
||||
def there_is_a_string_with_content(content, string):
|
||||
def _(content, string):
|
||||
string["content"] = content
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ def test_steps_in_feature_file_have_unicode(testdir):
|
|||
|
||||
|
||||
@then(parsers.parse("I should see that the string equals to content '{content}'"))
|
||||
def assert_that_the_string_equals_to_content(content, string):
|
||||
def _(content, string):
|
||||
assert string["content"] == content
|
||||
"""
|
||||
)
|
||||
|
@ -85,11 +85,11 @@ def test_steps_in_py_file_have_unicode(testdir):
|
|||
|
||||
|
||||
@given("there is an other string with content 'якийсь контент'")
|
||||
def there_is_an_other_string_with_content(string):
|
||||
def _(string):
|
||||
string["content"] = u"с каким-то контентом"
|
||||
|
||||
@then("I should see that the other string equals to content 'якийсь контент'")
|
||||
def assert_that_the_other_string_equals_to_content(string):
|
||||
def _(string):
|
||||
assert string["content"] == u"с каким-то контентом"
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue