diff --git a/tests/feature/test_outline_empty_values.py b/tests/feature/test_outline_empty_values.py index 6b8de580..329434b6 100644 --- a/tests/feature/test_outline_empty_values.py +++ b/tests/feature/test_outline_empty_values.py @@ -4,77 +4,36 @@ from pytest_bdd.utils import collect_dumped_objects +STEPS = """\ +from pytest_bdd import given, when, then, parsers +from pytest_bdd.utils import dump_obj -def test_scenario_with_empty_example_values(pytester): - pytester.makefile( - ".feature", - outline=textwrap.dedent( - """\ - Feature: Outline - Scenario Outline: Outlined with empty example values - Given there are cucumbers - When I eat cucumbers - Then I should have cucumbers +# Using `parsers.re` so that we can match empty values - Examples: - | start | eat | left | - | # | | | - """ - ), - ) - pytester.makeconftest( - textwrap.dedent( - """\ - from pytest_bdd import given, when, then, parsers - from pytest_bdd.utils import dump_obj +@given(parsers.re("there are (?P.*?) cucumbers")) +def _(start): + dump_obj(start) - # Using `parsers.re` so that we can match empty values - @given(parsers.re("there are (?P.*?) cucumbers")) - def _(start): - dump_obj(start) +@when(parsers.re("I eat (?P.*?) cucumbers")) +def _(eat): + dump_obj(eat) - @when(parsers.re("I eat (?P.*?) cucumbers")) - def _(eat): - dump_obj(eat) +@then(parsers.re("I should have (?P.*?) cucumbers")) +def _(left): + dump_obj(left) +""" - @then(parsers.re("I should have (?P.*?) cucumbers")) - def _(left): - dump_obj(left) - - """ - ) - ) - pytester.makepyfile( - textwrap.dedent( - """\ - from pytest_bdd import scenario - - @scenario("outline.feature", "Outlined with empty example values") - def test_outline(): - pass - """ - ) - ) - result = pytester.runpytest("-s") - result.assert_outcomes(passed=1) - assert collect_dumped_objects(result) == ["#", "", ""] - - -def test_scenario_with_empty_example_values_none_transformer(pytester): - """ - Checks that `parsers.re` can transform empty values to None with a converter. - `parsers.parse` and `parsers.cfparse` won't work out of the box this way as they will fail to match the steps. - """ +def test_scenario_with_empty_example_values(pytester): pytester.makefile( ".feature", outline=textwrap.dedent( """\ Feature: Outline - Scenario Outline: Outlined with empty example values and transformer + Scenario Outline: Outlined with empty example values Given there are cucumbers When I eat cucumbers Then I should have cucumbers @@ -85,46 +44,21 @@ def test_scenario_with_empty_example_values_none_transformer(pytester): """ ), ) - pytester.makeconftest( - textwrap.dedent( - """\ - from pytest_bdd import given, when, then, parsers - from pytest_bdd.utils import dump_obj - - - def empty_to_none(value): - return None if value.strip() == "" else value - - - @given(parsers.re("there are (?P.*?) cucumbers"), converters={"start": empty_to_none}) - def _(start): - dump_obj(start) - - - @when(parsers.re("I eat (?P.*?) cucumbers"), converters={"eat": empty_to_none}) - def _(eat): - dump_obj(eat) - - - @then(parsers.re("I should have (?P.*?) cucumbers"), converters={"left": empty_to_none}) - def _(left): - dump_obj(left) - - """ - ) - ) + pytester.makeconftest(textwrap.dedent(STEPS)) pytester.makepyfile( textwrap.dedent( """\ - from pytest_bdd import scenario + from pytest_bdd.utils import dump_obj + from pytest_bdd import scenario + import json - @scenario("outline.feature", "Outlined with empty example values and transformer") - def test_outline(): - pass - """ + @scenario("outline.feature", "Outlined with empty example values") + def test_outline(): + pass + """ ) ) result = pytester.runpytest("-s") result.assert_outcomes(passed=1) - assert collect_dumped_objects(result) == ["#", None, None] + assert collect_dumped_objects(result) == ["#", "", ""]