Lines """)[1:-1] ), ]) def test_multiline(request, tmpdir, feature_text, expected_text): file_name = tmpdir.join('test.feature') with file_name.open('w') as fd: fd.write(feature_text) @scenario(file_name.strpath, 'Multiline step using sub indentation') def test_multiline(request): assert request.getfuncargvalue('i_have_text') == expected_text test_multiline(request) @given(parsers.parse('I have a step with:\n{text}')) def i_have_text(text): return text @then('the text should be parsed with correct indentation') def text_should_be_correct(i_have_text, text, expected_text): assert i_have_text == text == expected_text def test_multiline_wrong_indent(request): """Multiline step using sub indentation wrong indent.""" @scenario( 'multiline.feature', 'Multiline step using sub indentation wrong indent', )
@scenario("args.feature", "Executed with tests matching step definitons with arguments") def test_steps(): pass @given('I have a foo fixture with value "foo"') def foo(): return "foo" @given("there is a list") def results(): return [] @when(parsers.parse("I append {n:d} to the list")) def append_to_list(results, n): results.append(n) @then('foo should have value "foo"') def foo_is_foo(foo): assert foo == "foo" @then("the list should be [1, 2, 3]") def check_results(results): assert results == [1, 2, 3]
@scenario(u"Steps in .py file have unicode") def test_steps_in_py_file_have_unicode(): pass pattern = "(?P<content>'\w+')" @pytest.fixture def string(): """String fixture.""" return {"content": ""} @given(parsers.parse(u"у мене є рядок який містить '{content}'")) def there_is_a_string_with_content(content, string): """Create string with unicode content.""" string["content"] = content @given("there is an other string with content 'якийсь контент'") def there_is_an_other_string_with_content(string): """Create other string with unicode content.""" string["content"] = u"с каким-то контентом" @then("I should see that the other string equals to content 'якийсь контент'") def assert_that_the_other_string_equals_to_content(string): """Assert that the other string equals to content.""" assert string["content"] == u"с каким-то контентом"
scenario( 'not_found.feature', 'NOT FOUND' ) assert six.text_type(exc_info.value).startswith( 'Scenario "NOT FOUND" in feature "[Empty]" in {feature_path}' .format(feature_path=request.fspath.join('..', 'not_found.feature'))) @given('comments should be at the start of words') def comments(): """Comments.""" pass @then(parsers.parse('this is not {acomment}')) def a_comment(acomment): """A comment.""" assert re.search('a.*comment', acomment) def test_scenario_comments(request): """Test comments inside scenario.""" @scenario( 'comments.feature', 'Comments' ) def test(): pass @scenario(
@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.parse('I have {euro:d} Euro')) def i_have(euro, values): assert euro == values.pop(0) @when(parsers.parse('I pay {euro:d} Euro')) def i_pay(euro, values, request): assert euro == values.pop(0) @then(parsers.parse('I should have {euro:d} Euro')) def i_should_have(euro, values): assert euro == values.pop(0) @given(parsers.parse('I have an argument {arg:Number}', extra_types=dict(Number=int)))