Exemplo n.º 1
0
    @scenario(
        "background.feature",
        "Background tests are executed first",
    )
    def test():
        pass

    test(request)


@pytest.fixture
def foo():
    return {}


@given(parsers.re(r'a background step with multiple lines:\n(?P<data>.+)', flags=re.DOTALL))
def multi_line(foo, data):
    assert data == "one\ntwo"


@given('foo has a value "bar"')
def bar(foo):
    foo["bar"] = "bar"
    return foo["bar"]


@given('foo has a value "dummy"')
def dummy(foo):
    foo["dummy"] = "dummy"
    return foo["dummy"]
Exemplo n.º 2
0
@scenario_when('Argument in when, step 2')
def test_argument_in_when_step_2():
    pass


def test_multiple_given(request):
    """Using the same given fixture raises an error."""
    @scenario_args('Using the same given fixture raises an error')
    def test():
        pass
    with pytest.raises(exceptions.GivenAlreadyUsed):
        test(request)


@given(parsers.re(r'I have (?P<euro>\d+) Euro'), converters=dict(euro=int))
def i_have(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):
    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):
    assert euro == values.pop(0)


# test backwards compartibility