forked from test_framework/pytest-bdd
tests: Use `pytester` fixture instead of `testdir`
`testdir` is deprecated. It's identical to `pytester`, except that `testdir` returns `py.path` objects whereas `pytester` returns Python stdlib `Path` objects. So I had to update usages of those paths. `pytester` was added in pytest 6.2, which is our minimum supported version.
This commit is contained in:
parent
3f6dc8744f
commit
c8677a7783
|
@ -68,7 +68,7 @@ def collect_dumped_objects(result: RunResult) -> list:
|
|||
"""Parse all the objects dumped with `dump_object` from the result.
|
||||
|
||||
Note: You must run the result with output to stdout enabled.
|
||||
For example, using ``testdir.runpytest("-s")``.
|
||||
For example, using ``pytester.runpytest("-s")``.
|
||||
"""
|
||||
stdout = result.stdout.str() # pytest < 6.2, otherwise we could just do str(result.stdout)
|
||||
payloads = re.findall(rf"{_DUMP_START}(.*?){_DUMP_END}", stdout)
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_every_step_takes_param_with_the_same_name(testdir):
|
||||
def test_every_step_takes_param_with_the_same_name(pytester):
|
||||
"""Test every step takes param with the same name."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -21,7 +21,7 @@ def test_every_step_takes_param_with_the_same_name(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -53,13 +53,13 @@ def test_every_step_takes_param_with_the_same_name(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_argument_in_when(testdir):
|
||||
def test_argument_in_when(pytester):
|
||||
"""Test step arguments in when steps."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -72,7 +72,7 @@ def test_argument_in_when(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -105,5 +105,5 @@ def test_argument_in_when(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_every_steps_takes_param_with_the_same_name(testdir):
|
||||
testdir.makefile(
|
||||
def test_every_steps_takes_param_with_the_same_name(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -20,7 +20,7 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -52,12 +52,12 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_argument_in_when_step_1(testdir):
|
||||
testdir.makefile(
|
||||
def test_argument_in_when_step_1(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -70,7 +70,7 @@ def test_argument_in_when_step_1(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -103,5 +103,5 @@ def test_argument_in_when_step_1(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_every_steps_takes_param_with_the_same_name(testdir):
|
||||
testdir.makefile(
|
||||
def test_every_steps_takes_param_with_the_same_name(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -20,7 +20,7 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
import pytest
|
||||
|
@ -51,17 +51,17 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_exact_match(testdir):
|
||||
def test_exact_match(pytester):
|
||||
"""Test that parsers.re does an exact match (fullmatch) of the whole string.
|
||||
|
||||
This tests exists because in the past we only used re.match, which only finds a match at the beginning
|
||||
of the string, so if there were any more characters not matching at the end, they were ignored"""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -75,7 +75,7 @@ def test_exact_match(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
import pytest
|
||||
|
@ -101,15 +101,15 @@ def test_exact_match(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
'*StepDefinitionNotFoundError: Step definition is not found: When "I pay 1 Euro by mistake"*'
|
||||
)
|
||||
|
||||
|
||||
def test_argument_in_when(testdir):
|
||||
testdir.makefile(
|
||||
def test_argument_in_when(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -122,7 +122,7 @@ def test_argument_in_when(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
import pytest
|
||||
|
@ -155,5 +155,5 @@ def test_argument_in_when(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -3,8 +3,8 @@ import textwrap
|
|||
from pytest_bdd.utils import collect_dumped_objects
|
||||
|
||||
|
||||
def test_reuse_same_step_different_converters(testdir):
|
||||
testdir.makefile(
|
||||
def test_reuse_same_step_different_converters(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -19,7 +19,7 @@ def test_reuse_same_step_different_converters(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
import pytest
|
||||
|
@ -43,7 +43,7 @@ def test_reuse_same_step_different_converters(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[int_value, str_value, float_value] = collect_dumped_objects(result)
|
||||
|
@ -57,9 +57,9 @@ def test_reuse_same_step_different_converters(testdir):
|
|||
assert float_value == 42.0
|
||||
|
||||
|
||||
def test_string_steps_dont_take_precedence(testdir):
|
||||
def test_string_steps_dont_take_precedence(pytester):
|
||||
"""Test that normal steps don't take precedence over the other steps."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
arguments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -71,7 +71,7 @@ def test_string_steps_dont_take_precedence(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
from pytest_bdd import given, when, then, parsers
|
||||
|
@ -92,7 +92,7 @@ def test_string_steps_dont_take_precedence(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
import pytest
|
||||
|
@ -109,7 +109,7 @@ def test_string_steps_dont_take_precedence(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[which] = collect_dumped_objects(result)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_step_alias(testdir):
|
||||
testdir.makefile(
|
||||
def test_step_alias(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
alias=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -22,7 +22,7 @@ def test_step_alias(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -56,5 +56,5 @@ def test_step_alias(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -73,13 +73,13 @@ def _(foo):
|
|||
"""
|
||||
|
||||
|
||||
def test_background_basic(testdir):
|
||||
def test_background_basic(pytester):
|
||||
"""Test feature background."""
|
||||
testdir.makefile(".feature", background=textwrap.dedent(FEATURE))
|
||||
pytester.makefile(".feature", background=textwrap.dedent(FEATURE))
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -91,18 +91,18 @@ def test_background_basic(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_background_check_order(testdir):
|
||||
def test_background_check_order(pytester):
|
||||
"""Test feature background to ensure that background steps are executed first."""
|
||||
|
||||
testdir.makefile(".feature", background=textwrap.dedent(FEATURE))
|
||||
pytester.makefile(".feature", background=textwrap.dedent(FEATURE))
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -114,5 +114,5 @@ def test_background_check_order(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -10,10 +10,10 @@ if TYPE_CHECKING:
|
|||
from _pytest.pytester import RunResult, Testdir
|
||||
|
||||
|
||||
def runandparse(testdir: Testdir, *args: Any) -> tuple[RunResult, list[dict[str, Any]]]:
|
||||
def runandparse(pytester: Pytester, *args: Any) -> tuple[RunResult, list[dict[str, Any]]]:
|
||||
"""Run tests in testdir and parse json output."""
|
||||
resultpath = testdir.tmpdir.join("cucumber.json")
|
||||
result = testdir.runpytest(f"--cucumberjson={resultpath}", "-s", *args)
|
||||
resultpath = pytester.path.joinpath("cucumber.json")
|
||||
result = pytester.runpytest(f"--cucumberjson={resultpath}", "-s", *args)
|
||||
with resultpath.open() as f:
|
||||
jsonobject = json.load(f)
|
||||
return result, jsonobject
|
||||
|
@ -29,9 +29,9 @@ class OfType:
|
|||
return isinstance(other, self.type) if self.type else True
|
||||
|
||||
|
||||
def test_step_trace(testdir):
|
||||
def test_step_trace(pytester):
|
||||
"""Test step trace."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".ini",
|
||||
pytest=textwrap.dedent(
|
||||
"""
|
||||
|
@ -44,7 +44,7 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test=textwrap.dedent(
|
||||
"""
|
||||
|
@ -73,7 +73,7 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
import pytest
|
||||
|
@ -109,7 +109,7 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result, jsonobject = runandparse(testdir)
|
||||
result, jsonobject = runandparse(pytester)
|
||||
result.assert_outcomes(passed=4, failed=1)
|
||||
|
||||
assert result.ret
|
||||
|
@ -227,7 +227,7 @@ def test_step_trace(testdir):
|
|||
"line": 2,
|
||||
"name": "One passing scenario, one failing scenario",
|
||||
"tags": [{"name": "feature-tag", "line": 1}],
|
||||
"uri": os.path.join(testdir.tmpdir.basename, "test.feature"),
|
||||
"uri": os.path.join(pytester.path.name, "test.feature"),
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_description(testdir):
|
||||
def test_description(pytester):
|
||||
"""Test description for the feature."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
description=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -24,7 +24,7 @@ def test_description(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import textwrap
|
||||
|
@ -53,5 +53,5 @@ def test_description(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=2)
|
||||
|
|
|
@ -5,44 +5,44 @@ NOT_EXISTING_FEATURE_PATHS = [".", "/does/not/exist/"]
|
|||
|
||||
|
||||
@pytest.mark.parametrize("base_dir", NOT_EXISTING_FEATURE_PATHS)
|
||||
def test_feature_path_not_found(testdir, base_dir):
|
||||
def test_feature_path_not_found(pytester, base_dir):
|
||||
"""Test feature base dir."""
|
||||
prepare_testdir(testdir, base_dir)
|
||||
prepare_testdir(pytester, base_dir)
|
||||
|
||||
result = testdir.runpytest("-k", "test_not_found_by_ini")
|
||||
result = pytester.runpytest("-k", "test_not_found_by_ini")
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
def test_feature_path_ok(testdir):
|
||||
def test_feature_path_ok(pytester):
|
||||
base_dir = "features"
|
||||
prepare_testdir(testdir, base_dir)
|
||||
prepare_testdir(pytester, base_dir)
|
||||
|
||||
result = testdir.runpytest("-k", "test_ok_by_ini")
|
||||
result = pytester.runpytest("-k", "test_ok_by_ini")
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
def test_feature_path_by_param_not_found(testdir):
|
||||
def test_feature_path_by_param_not_found(pytester):
|
||||
"""As param takes precedence even if ini config is correct it should fail
|
||||
if passed param is incorrect"""
|
||||
base_dir = "features"
|
||||
prepare_testdir(testdir, base_dir)
|
||||
prepare_testdir(pytester, base_dir)
|
||||
|
||||
result = testdir.runpytest("-k", "test_not_found_by_param")
|
||||
result = pytester.runpytest("-k", "test_not_found_by_param")
|
||||
result.assert_outcomes(passed=4)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_dir", NOT_EXISTING_FEATURE_PATHS)
|
||||
def test_feature_path_by_param_ok(testdir, base_dir):
|
||||
def test_feature_path_by_param_ok(pytester, base_dir):
|
||||
"""If ini config is incorrect but param path is fine it should be able
|
||||
to find features"""
|
||||
prepare_testdir(testdir, base_dir)
|
||||
prepare_testdir(pytester, base_dir)
|
||||
|
||||
result = testdir.runpytest("-k", "test_ok_by_param")
|
||||
result = pytester.runpytest("-k", "test_ok_by_param")
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
def prepare_testdir(testdir, ini_base_dir):
|
||||
testdir.makeini(
|
||||
def prepare_testdir(pytester, ini_base_dir):
|
||||
pytester.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
bdd_features_base_dir={}
|
||||
|
@ -51,8 +51,8 @@ def prepare_testdir(testdir, ini_base_dir):
|
|||
)
|
||||
)
|
||||
|
||||
feature_file = testdir.mkdir("features").join("steps.feature")
|
||||
feature_file.write(
|
||||
feature_file = pytester.mkdir("features").joinpath("steps.feature")
|
||||
feature_file.write_text(
|
||||
"""
|
||||
Feature: Feature path
|
||||
Scenario: When scenario found
|
||||
|
@ -60,7 +60,7 @@ def prepare_testdir(testdir, ini_base_dir):
|
|||
"""
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import os.path
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ def test_scenario_1():
|
|||
"""
|
||||
|
||||
|
||||
def test_default_output_should_be_the_same_as_regular_terminal_reporter(testdir):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(TEST)
|
||||
regular = testdir.runpytest()
|
||||
gherkin = testdir.runpytest("--gherkin-terminal-reporter")
|
||||
def test_default_output_should_be_the_same_as_regular_terminal_reporter(pytester):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(TEST)
|
||||
regular = pytester.runpytest()
|
||||
gherkin = pytester.runpytest("--gherkin-terminal-reporter")
|
||||
regular.assert_outcomes(passed=1, failed=0)
|
||||
gherkin.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
@ -51,17 +51,17 @@ def test_default_output_should_be_the_same_as_regular_terminal_reporter(testdir)
|
|||
assert all(l1 == l2 for l1, l2 in zip(parse_lines(regular.stdout.lines), parse_lines(gherkin.stdout.lines)))
|
||||
|
||||
|
||||
def test_verbose_mode_should_display_feature_and_scenario_names_instead_of_test_names_in_a_single_line(testdir):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(TEST)
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", "-v")
|
||||
def test_verbose_mode_should_display_feature_and_scenario_names_instead_of_test_names_in_a_single_line(pytester):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(TEST)
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", "-v")
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
result.stdout.fnmatch_lines("Feature: Gherkin terminal output feature")
|
||||
result.stdout.fnmatch_lines("*Scenario: Scenario example 1 PASSED")
|
||||
|
||||
|
||||
def test_verbose_mode_should_preserve_displaying_regular_tests_as_usual(testdir):
|
||||
testdir.makepyfile(
|
||||
def test_verbose_mode_should_preserve_displaying_regular_tests_as_usual(pytester):
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
def test_1():
|
||||
|
@ -69,8 +69,8 @@ def test_verbose_mode_should_preserve_displaying_regular_tests_as_usual(testdir)
|
|||
"""
|
||||
)
|
||||
)
|
||||
regular = testdir.runpytest()
|
||||
gherkin = testdir.runpytest("--gherkin-terminal-reporter", "-v")
|
||||
regular = pytester.runpytest()
|
||||
gherkin = pytester.runpytest("--gherkin-terminal-reporter", "-v")
|
||||
regular.assert_outcomes(passed=1, failed=0)
|
||||
gherkin.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
@ -80,10 +80,10 @@ def test_verbose_mode_should_preserve_displaying_regular_tests_as_usual(testdir)
|
|||
)
|
||||
|
||||
|
||||
def test_double_verbose_mode_should_display_full_scenario_description(testdir):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(TEST)
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", "-vv")
|
||||
def test_double_verbose_mode_should_display_full_scenario_description(pytester):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(TEST)
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", "-vv")
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
result.stdout.fnmatch_lines("*Scenario: Scenario example 1")
|
||||
|
@ -94,9 +94,9 @@ def test_double_verbose_mode_should_display_full_scenario_description(testdir):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("verbosity", ["", "-v", "-vv"])
|
||||
def test_error_message_for_missing_steps(testdir, verbosity):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(
|
||||
def test_error_message_for_missing_steps(pytester, verbosity):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenarios
|
||||
|
@ -105,7 +105,7 @@ def test_error_message_for_missing_steps(testdir, verbosity):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", verbosity)
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", verbosity)
|
||||
result.assert_outcomes(passed=0, failed=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
"""*StepDefinitionNotFoundError: Step definition is not found: Given "there is a bar". """
|
||||
|
@ -114,9 +114,9 @@ def test_error_message_for_missing_steps(testdir, verbosity):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("verbosity", ["", "-v", "-vv"])
|
||||
def test_error_message_should_be_displayed(testdir, verbosity):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(
|
||||
def test_error_message_should_be_displayed(pytester, verbosity):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, then, scenario
|
||||
|
@ -142,15 +142,15 @@ def test_error_message_should_be_displayed(testdir, verbosity):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", verbosity)
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", verbosity)
|
||||
result.assert_outcomes(passed=0, failed=1)
|
||||
result.stdout.fnmatch_lines("E Exception: BIGBADABOOM")
|
||||
result.stdout.fnmatch_lines("test_error_message_should_be_displayed.py:15: Exception")
|
||||
|
||||
|
||||
def test_local_variables_should_be_displayed_when_showlocals_option_is_used(testdir):
|
||||
testdir.makefile(".feature", test=FEATURE)
|
||||
testdir.makepyfile(
|
||||
def test_local_variables_should_be_displayed_when_showlocals_option_is_used(pytester):
|
||||
pytester.makefile(".feature", test=FEATURE)
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, then, scenario
|
||||
|
@ -177,15 +177,15 @@ def test_local_variables_should_be_displayed_when_showlocals_option_is_used(test
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", "--showlocals")
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", "--showlocals")
|
||||
result.assert_outcomes(passed=0, failed=1)
|
||||
result.stdout.fnmatch_lines("""request*=*<FixtureRequest for *""")
|
||||
result.stdout.fnmatch_lines("""local_var*=*MULTIPASS*""")
|
||||
|
||||
|
||||
def test_step_parameters_should_be_replaced_by_their_values(testdir):
|
||||
def test_step_parameters_should_be_replaced_by_their_values(pytester):
|
||||
example = {"start": 10, "eat": 3, "left": 7}
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -203,7 +203,7 @@ def test_step_parameters_should_be_replaced_by_their_values(testdir):
|
|||
)
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
test_gherkin=textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, scenario, then, parsers
|
||||
|
@ -227,7 +227,7 @@ def test_step_parameters_should_be_replaced_by_their_values(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("--gherkin-terminal-reporter", "-vv")
|
||||
result = pytester.runpytest("--gherkin-terminal-reporter", "-vv")
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
result.stdout.fnmatch_lines("*Scenario: Scenario example 2")
|
||||
result.stdout.fnmatch_lines("*Given there are {start} cucumbers".format(**example))
|
||||
|
|
|
@ -71,10 +71,10 @@ import pytest
|
|||
),
|
||||
],
|
||||
)
|
||||
def test_multiline(testdir, feature_text, expected_text):
|
||||
testdir.makefile(".feature", multiline=feature_text)
|
||||
def test_multiline(pytester, feature_text, expected_text):
|
||||
pytester.makefile(".feature", multiline=feature_text)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import parsers, given, then, scenario
|
||||
|
@ -101,14 +101,14 @@ def test_multiline(testdir, feature_text, expected_text):
|
|||
)
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_multiline_wrong_indent(testdir):
|
||||
def test_multiline_wrong_indent(pytester):
|
||||
"""Multiline step using sub indentation wrong indent."""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
multiline=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -126,7 +126,7 @@ def test_multiline_wrong_indent(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import parsers, given, then, scenario
|
||||
|
@ -149,6 +149,6 @@ def test_multiline_wrong_indent(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines("*StepDefinitionNotFoundError: Step definition is not found:*")
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_no_scenarios(testdir):
|
||||
def test_no_scenarios(pytester):
|
||||
"""Test no scenarios defined in the feature file."""
|
||||
features = testdir.mkdir("features")
|
||||
features.join("test.feature").write_text(
|
||||
features = pytester.mkdir("features")
|
||||
features.joinpath("test.feature").write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
Given foo
|
||||
|
@ -14,10 +14,9 @@ def test_no_scenarios(testdir):
|
|||
Then baz
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
|
||||
|
@ -27,5 +26,5 @@ def test_no_scenarios(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(["*FeatureError: Step definition outside of a Scenario or a Background.*"])
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
"""Test no strict gherkin for sections."""
|
||||
|
||||
|
||||
def test_background_no_strict_gherkin(testdir):
|
||||
def test_background_no_strict_gherkin(pytester):
|
||||
"""Test background no strict gherkin."""
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
test_gherkin="""
|
||||
import pytest
|
||||
|
||||
|
@ -38,7 +38,7 @@ def test_background_no_strict_gherkin(testdir):
|
|||
"""
|
||||
)
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
no_strict_gherkin_background="""
|
||||
Feature: No strict Gherkin Background support
|
||||
|
@ -53,13 +53,13 @@ def test_background_no_strict_gherkin(testdir):
|
|||
""",
|
||||
)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_scenario_no_strict_gherkin(testdir):
|
||||
def test_scenario_no_strict_gherkin(pytester):
|
||||
"""Test scenario no strict gherkin."""
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
test_gherkin="""
|
||||
import pytest
|
||||
|
||||
|
@ -94,7 +94,7 @@ def test_scenario_no_strict_gherkin(testdir):
|
|||
"""
|
||||
)
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
no_strict_gherkin_scenario="""
|
||||
Feature: No strict Gherkin Scenario support
|
||||
|
@ -107,5 +107,5 @@ def test_scenario_no_strict_gherkin(testdir):
|
|||
""",
|
||||
)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -31,8 +31,8 @@ def _(cucumbers, left):
|
|||
"""
|
||||
|
||||
|
||||
def test_outlined(testdir):
|
||||
testdir.makefile(
|
||||
def test_outlined(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -51,9 +51,9 @@ def test_outlined(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -68,7 +68,7 @@ def test_outlined(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=2)
|
||||
# fmt: off
|
||||
assert collect_dumped_objects(result) == [
|
||||
|
@ -78,10 +78,10 @@ def test_outlined(testdir):
|
|||
# fmt: on
|
||||
|
||||
|
||||
def test_unused_params(testdir):
|
||||
def test_unused_params(pytester):
|
||||
"""Test parametrized scenario when the test function lacks parameters."""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -99,9 +99,9 @@ def test_unused_params(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -112,13 +112,13 @@ def test_unused_params(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_outlined_with_other_fixtures(testdir):
|
||||
def test_outlined_with_other_fixtures(pytester):
|
||||
"""Test outlined scenario also using other parametrized fixture."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -137,9 +137,9 @@ def test_outlined_with_other_fixtures(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -161,13 +161,13 @@ def test_outlined_with_other_fixtures(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=6)
|
||||
|
||||
|
||||
def test_outline_with_escaped_pipes(testdir):
|
||||
def test_outline_with_escaped_pipes(pytester):
|
||||
"""Test parametrized feature example table with escaped pipe characters in input."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
r"""\
|
||||
|
@ -190,7 +190,7 @@ def test_outline_with_escaped_pipes(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario, given, parsers
|
||||
|
@ -208,7 +208,7 @@ def test_outline_with_escaped_pipes(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=7)
|
||||
assert collect_dumped_objects(result) == [
|
||||
r"bork",
|
||||
|
|
|
@ -26,8 +26,8 @@ def _(left):
|
|||
"""
|
||||
|
||||
|
||||
def test_scenario_with_empty_example_values(testdir):
|
||||
testdir.makefile(
|
||||
def test_scenario_with_empty_example_values(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
outline=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -43,9 +43,9 @@ def test_scenario_with_empty_example_values(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(textwrap.dedent(STEPS))
|
||||
pytester.makeconftest(textwrap.dedent(STEPS))
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd.utils import dump_obj
|
||||
|
@ -58,6 +58,6 @@ def test_scenario_with_empty_example_values(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
assert collect_dumped_objects(result) == ["#", "", ""]
|
||||
|
|
|
@ -14,9 +14,9 @@ class OfType:
|
|||
return isinstance(other, self.type) if self.type else True
|
||||
|
||||
|
||||
def test_step_trace(testdir):
|
||||
def test_step_trace(pytester):
|
||||
"""Test step trace."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".ini",
|
||||
pytest=textwrap.dedent(
|
||||
"""
|
||||
|
@ -28,7 +28,7 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
feature = testdir.makefile(
|
||||
feature = pytester.makefile(
|
||||
".feature",
|
||||
test=textwrap.dedent(
|
||||
"""
|
||||
|
@ -57,8 +57,8 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
relpath = feature.relto(testdir.tmpdir.dirname)
|
||||
testdir.makepyfile(
|
||||
relpath = feature.relative_to(pytester.path.parent)
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
import pytest
|
||||
|
@ -98,16 +98,16 @@ def test_step_trace(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.inline_run("-vvl")
|
||||
result = pytester.inline_run("-vvl")
|
||||
assert result.ret
|
||||
report = result.matchreport("test_passing", when="call").scenario
|
||||
expected = {
|
||||
"feature": {
|
||||
"description": "",
|
||||
"filename": feature.strpath,
|
||||
"filename": str(feature),
|
||||
"line_number": 2,
|
||||
"name": "One passing scenario, one failing scenario",
|
||||
"rel_filename": relpath,
|
||||
"rel_filename": str(relpath),
|
||||
"tags": ["feature-tag"],
|
||||
},
|
||||
"line_number": 5,
|
||||
|
@ -139,10 +139,10 @@ def test_step_trace(testdir):
|
|||
expected = {
|
||||
"feature": {
|
||||
"description": "",
|
||||
"filename": feature.strpath,
|
||||
"filename": str(feature),
|
||||
"line_number": 2,
|
||||
"name": "One passing scenario, one failing scenario",
|
||||
"rel_filename": relpath,
|
||||
"rel_filename": str(relpath),
|
||||
"tags": ["feature-tag"],
|
||||
},
|
||||
"line_number": 10,
|
||||
|
@ -173,10 +173,10 @@ def test_step_trace(testdir):
|
|||
expected = {
|
||||
"feature": {
|
||||
"description": "",
|
||||
"filename": feature.strpath,
|
||||
"filename": str(feature),
|
||||
"line_number": 2,
|
||||
"name": "One passing scenario, one failing scenario",
|
||||
"rel_filename": relpath,
|
||||
"rel_filename": str(relpath),
|
||||
"tags": ["feature-tag"],
|
||||
},
|
||||
"line_number": 14,
|
||||
|
@ -215,10 +215,10 @@ def test_step_trace(testdir):
|
|||
expected = {
|
||||
"feature": {
|
||||
"description": "",
|
||||
"filename": feature.strpath,
|
||||
"filename": str(feature),
|
||||
"line_number": 2,
|
||||
"name": "One passing scenario, one failing scenario",
|
||||
"rel_filename": relpath,
|
||||
"rel_filename": str(relpath),
|
||||
"tags": ["feature-tag"],
|
||||
},
|
||||
"line_number": 14,
|
||||
|
@ -254,14 +254,14 @@ def test_step_trace(testdir):
|
|||
assert report == expected
|
||||
|
||||
|
||||
def test_complex_types(testdir, pytestconfig):
|
||||
def test_complex_types(pytester, pytestconfig):
|
||||
"""Test serialization of the complex types."""
|
||||
if not pytestconfig.pluginmanager.has_plugin("xdist"):
|
||||
pytest.skip("Execnet not installed")
|
||||
|
||||
import execnet.gateway_base
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test=textwrap.dedent(
|
||||
"""
|
||||
|
@ -276,7 +276,7 @@ def test_complex_types(testdir, pytestconfig):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
import pytest
|
||||
|
@ -313,7 +313,7 @@ def test_complex_types(testdir, pytestconfig):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.inline_run("-vvl")
|
||||
result = pytester.inline_run("-vvl")
|
||||
report = result.matchreport("test_complex[10,20-alien0]", when="call")
|
||||
assert report.passed
|
||||
assert execnet.gateway_base.dumps(report.item)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_when_function_name_same_as_step_name(testdir):
|
||||
testdir.makefile(
|
||||
def test_when_function_name_same_as_step_name(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
same_name=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -14,7 +14,7 @@ def test_when_function_name_same_as_step_name(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import when, scenario
|
||||
|
@ -29,5 +29,5 @@ def test_when_function_name_same_as_step_name(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_scenario_not_found(testdir, pytest_params):
|
||||
def test_scenario_not_found(pytester, pytest_params):
|
||||
"""Test the situation when scenario is not found."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
not_found=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -14,7 +14,7 @@ def test_scenario_not_found(testdir, pytest_params):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import re
|
||||
|
@ -28,15 +28,15 @@ def test_scenario_not_found(testdir, pytest_params):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest_subprocess(*pytest_params)
|
||||
result = pytester.runpytest_subprocess(*pytest_params)
|
||||
|
||||
result.assert_outcomes(errors=1)
|
||||
result.stdout.fnmatch_lines('*Scenario "NOT FOUND" in feature "Scenario is not found" in*')
|
||||
|
||||
|
||||
def test_scenario_comments(testdir):
|
||||
def test_scenario_comments(pytester):
|
||||
"""Test comments inside scenario."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
comments=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -54,7 +54,7 @@ def test_scenario_comments(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import re
|
||||
|
@ -88,14 +88,14 @@ def test_scenario_comments(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
def test_scenario_not_decorator(testdir, pytest_params):
|
||||
def test_scenario_not_decorator(pytester, pytest_params):
|
||||
"""Test scenario function is used not as decorator."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
foo="""
|
||||
Feature: Test function is not a decorator
|
||||
|
@ -103,7 +103,7 @@ def test_scenario_not_decorator(testdir, pytest_params):
|
|||
Given I have a bar
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import scenario
|
||||
|
||||
|
@ -111,15 +111,15 @@ def test_scenario_not_decorator(testdir, pytest_params):
|
|||
"""
|
||||
)
|
||||
|
||||
result = testdir.runpytest_subprocess(*pytest_params)
|
||||
result = pytester.runpytest_subprocess(*pytest_params)
|
||||
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines("*ScenarioIsDecoratorOnly: scenario function can only be used as a decorator*")
|
||||
|
||||
|
||||
def test_simple(testdir, pytest_params):
|
||||
def test_simple(pytester, pytest_params):
|
||||
"""Test scenario decorator with a standard usage."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
simple="""
|
||||
Feature: Simple feature
|
||||
|
@ -127,7 +127,7 @@ def test_simple(testdir, pytest_params):
|
|||
Given I have a bar
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import scenario, given, then
|
||||
|
||||
|
@ -144,17 +144,17 @@ def test_simple(testdir, pytest_params):
|
|||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess(*pytest_params)
|
||||
result = pytester.runpytest_subprocess(*pytest_params)
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_angular_brakets_are_not_parsed(testdir):
|
||||
def test_angular_brakets_are_not_parsed(pytester):
|
||||
"""Test that angular brackets are not parsed for "Scenario"s.
|
||||
|
||||
(They should be parsed only when used in "Scenario Outline")
|
||||
|
||||
"""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
simple="""
|
||||
Feature: Simple feature
|
||||
|
@ -171,7 +171,7 @@ def test_angular_brakets_are_not_parsed(testdir):
|
|||
| bar |
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import scenarios, given, then, parsers
|
||||
|
||||
|
@ -190,5 +190,5 @@ def test_angular_brakets_are_not_parsed(testdir):
|
|||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=2)
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_scenarios(testdir, pytest_params):
|
||||
def test_scenarios(pytester, pytest_params):
|
||||
"""Test scenarios shortcut (used together with @scenario for individual test override)."""
|
||||
testdir.makeini(
|
||||
pytester.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
console_output_style=classic
|
||||
"""
|
||||
)
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import given
|
||||
|
@ -21,8 +21,8 @@ def test_scenarios(testdir, pytest_params):
|
|||
return 'bar'
|
||||
"""
|
||||
)
|
||||
features = testdir.mkdir("features")
|
||||
features.join("test.feature").write_text(
|
||||
features = pytester.mkdir("features")
|
||||
features.joinpath("test.feature").write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
Scenario: Test scenario
|
||||
|
@ -30,9 +30,10 @@ def test_scenarios(testdir, pytest_params):
|
|||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
features.join("subfolder", "test.feature").write_text(
|
||||
subfolder = features.joinpath("subfolder")
|
||||
subfolder.mkdir()
|
||||
subfolder.joinpath("test.feature").write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
Scenario: Test subfolder scenario
|
||||
|
@ -49,9 +50,8 @@ def test_scenarios(testdir, pytest_params):
|
|||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import scenarios, scenario
|
||||
|
@ -63,7 +63,7 @@ def test_scenarios(testdir, pytest_params):
|
|||
scenarios('features')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess("-v", "-s", *pytest_params)
|
||||
result = pytester.runpytest_subprocess("-v", "-s", *pytest_params)
|
||||
result.assert_outcomes(passed=4, failed=1)
|
||||
result.stdout.fnmatch_lines(["*collected 5 items"])
|
||||
result.stdout.fnmatch_lines(["*test_test_subfolder_scenario *bar!", "PASSED"])
|
||||
|
@ -73,9 +73,9 @@ def test_scenarios(testdir, pytest_params):
|
|||
result.stdout.fnmatch_lines(["*test_test_scenario_1 *bar!", "PASSED"])
|
||||
|
||||
|
||||
def test_scenarios_none_found(testdir, pytest_params):
|
||||
def test_scenarios_none_found(pytester, pytest_params):
|
||||
"""Test scenarios shortcut when no scenarios found."""
|
||||
testpath = testdir.makepyfile(
|
||||
testpath = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import scenarios
|
||||
|
@ -83,6 +83,6 @@ def test_scenarios_none_found(testdir, pytest_params):
|
|||
scenarios('.')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess(testpath, *pytest_params)
|
||||
result = pytester.runpytest_subprocess(testpath, *pytest_params)
|
||||
result.assert_outcomes(errors=1)
|
||||
result.stdout.fnmatch_lines(["*NoScenariosFound*"])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_steps(testdir):
|
||||
testdir.makefile(
|
||||
def test_steps(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -22,7 +22,7 @@ def test_steps(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, then, scenario
|
||||
|
@ -68,12 +68,12 @@ def test_steps(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_step_function_can_be_decorated_multiple_times(testdir):
|
||||
testdir.makefile(
|
||||
def test_step_function_can_be_decorated_multiple_times(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -90,7 +90,7 @@ def test_step_function_can_be_decorated_multiple_times(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, then, scenario, parsers
|
||||
|
@ -120,13 +120,13 @@ def test_step_function_can_be_decorated_multiple_times(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_all_steps_can_provide_fixtures(testdir):
|
||||
def test_all_steps_can_provide_fixtures(pytester):
|
||||
"""Test that given/when/then can all provide fixtures."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -144,7 +144,7 @@ def test_all_steps_can_provide_fixtures(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, when, then, parsers, scenarios
|
||||
|
@ -173,12 +173,12 @@ def test_all_steps_can_provide_fixtures(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=3, failed=0)
|
||||
|
||||
|
||||
def test_when_first(testdir):
|
||||
testdir.makefile(
|
||||
def test_when_first(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -192,7 +192,7 @@ def test_when_first(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import when, then, scenario
|
||||
|
@ -213,12 +213,12 @@ def test_when_first(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_then_after_given(testdir):
|
||||
testdir.makefile(
|
||||
def test_then_after_given(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -233,7 +233,7 @@ def test_then_after_given(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, then, scenario
|
||||
|
@ -253,12 +253,12 @@ def test_then_after_given(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_conftest(testdir):
|
||||
testdir.makefile(
|
||||
def test_conftest(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -273,7 +273,7 @@ def test_conftest(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, then
|
||||
|
@ -291,7 +291,7 @@ def test_conftest(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -303,13 +303,13 @@ def test_conftest(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_multiple_given(testdir):
|
||||
def test_multiple_given(pytester):
|
||||
"""Using the same given fixture raises an error."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
steps=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -322,7 +322,7 @@ def test_multiple_given(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import parsers, given, then, scenario
|
||||
|
@ -345,13 +345,13 @@ def test_multiple_given(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1, failed=0)
|
||||
|
||||
|
||||
def test_step_hooks(testdir):
|
||||
def test_step_hooks(pytester):
|
||||
"""When step fails."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Scenario: When step has hook on failure
|
||||
|
@ -370,7 +370,7 @@ def test_step_hooks(testdir):
|
|||
And foo
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import given, when, scenario
|
||||
|
@ -416,7 +416,7 @@ def test_step_hooks(testdir):
|
|||
pass
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run("-k test_when_fails")
|
||||
reprec = pytester.inline_run("-k test_when_fails")
|
||||
reprec.assertoutcome(failed=1)
|
||||
|
||||
calls = reprec.getcalls("pytest_bdd_before_scenario")
|
||||
|
@ -437,16 +437,16 @@ def test_step_hooks(testdir):
|
|||
calls = reprec.getcalls("pytest_bdd_step_error")
|
||||
assert calls[0].request
|
||||
|
||||
reprec = testdir.inline_run("-k test_when_not_found")
|
||||
reprec = pytester.inline_run("-k test_when_not_found")
|
||||
reprec.assertoutcome(failed=1)
|
||||
|
||||
calls = reprec.getcalls("pytest_bdd_step_func_lookup_error")
|
||||
assert calls[0].request
|
||||
|
||||
reprec = testdir.inline_run("-k test_when_step_validation_error")
|
||||
reprec = pytester.inline_run("-k test_when_step_validation_error")
|
||||
reprec.assertoutcome(failed=1)
|
||||
|
||||
reprec = testdir.inline_run("-k test_when_dependency_fails", "-vv")
|
||||
reprec = pytester.inline_run("-k test_when_dependency_fails", "-vv")
|
||||
reprec.assertoutcome(failed=1)
|
||||
|
||||
calls = reprec.getcalls("pytest_bdd_before_step")
|
||||
|
@ -459,16 +459,16 @@ def test_step_hooks(testdir):
|
|||
assert calls[0].request
|
||||
|
||||
|
||||
def test_step_trace(testdir):
|
||||
def test_step_trace(pytester):
|
||||
"""Test step trace."""
|
||||
testdir.makeini(
|
||||
pytester.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
console_output_style=classic
|
||||
"""
|
||||
)
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Scenario: When step has failure
|
||||
|
@ -483,7 +483,7 @@ def test_step_trace(testdir):
|
|||
And foo
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import given, when, scenario
|
||||
|
@ -517,32 +517,32 @@ def test_step_trace(testdir):
|
|||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-k test_when_fails_inline", "-vv")
|
||||
result = pytester.runpytest("-k test_when_fails_inline", "-vv")
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines(["*test_when_fails_inline*FAILED"])
|
||||
assert "INTERNALERROR" not in result.stdout.str()
|
||||
|
||||
result = testdir.runpytest("-k test_when_fails_decorated", "-vv")
|
||||
result = pytester.runpytest("-k test_when_fails_decorated", "-vv")
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines(["*test_when_fails_decorated*FAILED"])
|
||||
assert "INTERNALERROR" not in result.stdout.str()
|
||||
|
||||
result = testdir.runpytest("-k test_when_not_found", "-vv")
|
||||
result = pytester.runpytest("-k test_when_not_found", "-vv")
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines(["*test_when_not_found*FAILED"])
|
||||
assert "INTERNALERROR" not in result.stdout.str()
|
||||
|
||||
result = testdir.runpytest("-k test_when_step_validation_error", "-vv")
|
||||
result = pytester.runpytest("-k test_when_step_validation_error", "-vv")
|
||||
result.assert_outcomes(failed=1)
|
||||
result.stdout.fnmatch_lines(["*test_when_step_validation_error*FAILED"])
|
||||
assert "INTERNALERROR" not in result.stdout.str()
|
||||
|
||||
|
||||
def test_steps_with_yield(testdir):
|
||||
def test_steps_with_yield(pytester):
|
||||
"""Test that steps definition containing a yield statement work the same way as
|
||||
pytest fixture do, that is the code after the yield is executed during teardown."""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
a="""\
|
||||
Feature: A feature
|
||||
|
@ -552,7 +552,7 @@ Feature: A feature
|
|||
Then stuff should be 42
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -575,7 +575,7 @@ Feature: A feature
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
|
|
|
@ -7,9 +7,9 @@ import pytest
|
|||
from pytest_bdd.parser import get_tags
|
||||
|
||||
|
||||
def test_tags_selector(testdir):
|
||||
def test_tags_selector(pytester):
|
||||
"""Test tests selection by tags."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".ini",
|
||||
pytest=textwrap.dedent(
|
||||
"""
|
||||
|
@ -24,7 +24,7 @@ def test_tags_selector(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
@feature_tag_1 @feature_tag_2
|
||||
|
@ -40,7 +40,7 @@ def test_tags_selector(testdir):
|
|||
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import given, scenarios
|
||||
|
@ -52,25 +52,25 @@ def test_tags_selector(testdir):
|
|||
scenarios('test.feature')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-m", "scenario_tag_10 and not scenario_tag_01", "-vv")
|
||||
result = pytester.runpytest("-m", "scenario_tag_10 and not scenario_tag_01", "-vv")
|
||||
outcomes = result.parseoutcomes()
|
||||
assert outcomes["passed"] == 1
|
||||
assert outcomes["deselected"] == 1
|
||||
|
||||
result = testdir.runpytest("-m", "scenario_tag_01 and not scenario_tag_10", "-vv").parseoutcomes()
|
||||
result = pytester.runpytest("-m", "scenario_tag_01 and not scenario_tag_10", "-vv").parseoutcomes()
|
||||
assert result["passed"] == 1
|
||||
assert result["deselected"] == 1
|
||||
|
||||
result = testdir.runpytest("-m", "feature_tag_1", "-vv").parseoutcomes()
|
||||
result = pytester.runpytest("-m", "feature_tag_1", "-vv").parseoutcomes()
|
||||
assert result["passed"] == 2
|
||||
|
||||
result = testdir.runpytest("-m", "feature_tag_10", "-vv").parseoutcomes()
|
||||
result = pytester.runpytest("-m", "feature_tag_10", "-vv").parseoutcomes()
|
||||
assert result["deselected"] == 2
|
||||
|
||||
|
||||
def test_tags_after_background_issue_160(testdir):
|
||||
def test_tags_after_background_issue_160(pytester):
|
||||
"""Make sure using a tag after background works."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".ini",
|
||||
pytest=textwrap.dedent(
|
||||
"""
|
||||
|
@ -79,7 +79,7 @@ def test_tags_after_background_issue_160(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Feature: Tags after background
|
||||
|
@ -95,7 +95,7 @@ def test_tags_after_background_issue_160(testdir):
|
|||
Given I have a baz
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
from pytest_bdd import given, scenarios
|
||||
|
@ -111,13 +111,13 @@ def test_tags_after_background_issue_160(testdir):
|
|||
scenarios('test.feature')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-m", "tag", "-vv").parseoutcomes()
|
||||
result = pytester.runpytest("-m", "tag", "-vv").parseoutcomes()
|
||||
assert result["passed"] == 1
|
||||
assert result["deselected"] == 1
|
||||
|
||||
|
||||
def test_apply_tag_hook(testdir):
|
||||
testdir.makeconftest(
|
||||
def test_apply_tag_hook(pytester):
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
|
@ -132,7 +132,7 @@ def test_apply_tag_hook(testdir):
|
|||
return None
|
||||
"""
|
||||
)
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Feature: Customizing tag handling
|
||||
|
@ -146,7 +146,7 @@ def test_apply_tag_hook(testdir):
|
|||
Given I have a bar
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import given, scenarios
|
||||
|
||||
|
@ -157,13 +157,13 @@ def test_apply_tag_hook(testdir):
|
|||
scenarios('test.feature')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-rsx")
|
||||
result = pytester.runpytest("-rsx")
|
||||
result.stdout.fnmatch_lines(["SKIP*: Not implemented yet"])
|
||||
result.stdout.fnmatch_lines(["*= 1 skipped, 1 xpassed * =*"])
|
||||
|
||||
|
||||
def test_tag_with_spaces(testdir):
|
||||
testdir.makefile(
|
||||
def test_tag_with_spaces(pytester):
|
||||
pytester.makefile(
|
||||
".ini",
|
||||
pytest=textwrap.dedent(
|
||||
"""
|
||||
|
@ -173,7 +173,7 @@ def test_tag_with_spaces(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
|
@ -182,7 +182,7 @@ def test_tag_with_spaces(testdir):
|
|||
assert tag == 'test with spaces'
|
||||
"""
|
||||
)
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Feature: Tag with spaces
|
||||
|
@ -192,7 +192,7 @@ def test_tag_with_spaces(testdir):
|
|||
Given I have a bar
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import given, scenarios
|
||||
|
||||
|
@ -203,12 +203,12 @@ def test_tag_with_spaces(testdir):
|
|||
scenarios('test.feature')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess()
|
||||
result = pytester.runpytest_subprocess()
|
||||
result.stdout.fnmatch_lines(["*= 1 passed * =*"])
|
||||
|
||||
|
||||
def test_at_in_scenario(testdir):
|
||||
testdir.makefile(
|
||||
def test_at_in_scenario(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
test="""
|
||||
Feature: At sign in a scenario
|
||||
|
@ -220,7 +220,7 @@ def test_at_in_scenario(testdir):
|
|||
Given I have a baz
|
||||
""",
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from pytest_bdd import given, scenarios
|
||||
|
||||
|
@ -243,7 +243,7 @@ def test_at_in_scenario(testdir):
|
|||
strict_option = "--strict-markers"
|
||||
else:
|
||||
strict_option = "--strict"
|
||||
result = testdir.runpytest_subprocess(strict_option)
|
||||
result = pytester.runpytest_subprocess(strict_option)
|
||||
result.stdout.fnmatch_lines(["*= 2 passed * =*"])
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_multiple_features_single_file(testdir):
|
||||
def test_multiple_features_single_file(pytester):
|
||||
"""Test validation error when multiple features are placed in a single file."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
wrong=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -35,7 +35,7 @@ def test_multiple_features_single_file(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -48,6 +48,6 @@ def test_multiple_features_single_file(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(errors=1)
|
||||
result.stdout.fnmatch_lines("*FeatureError: Multiple features are not allowed in a single feature file.*")
|
||||
|
|
|
@ -14,9 +14,9 @@ def test_python_name_generator():
|
|||
]
|
||||
|
||||
|
||||
def test_generate_missing(testdir):
|
||||
def test_generate_missing(pytester):
|
||||
"""Test generate missing command."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
generation=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -39,7 +39,7 @@ def test_generate_missing(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import functools
|
||||
|
@ -63,7 +63,7 @@ def test_generate_missing(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("--generate-missing", "--feature", "generation.feature")
|
||||
result = pytester.runpytest("--generate-missing", "--feature", "generation.feature")
|
||||
result.assert_outcomes(passed=0, failed=0, errors=0)
|
||||
assert not result.stderr.str()
|
||||
assert result.ret == 0
|
||||
|
@ -86,9 +86,9 @@ def test_generate_missing(testdir):
|
|||
result.stdout.fnmatch_lines(["Please place the code above to the test file(s):"])
|
||||
|
||||
|
||||
def test_generate_missing_with_step_parsers(testdir):
|
||||
def test_generate_missing_with_step_parsers(pytester):
|
||||
"""Test that step parsers are correctly discovered and won't be part of the missing steps."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
generation=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -103,7 +103,7 @@ def test_generate_missing_with_step_parsers(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import functools
|
||||
|
@ -131,7 +131,7 @@ def test_generate_missing_with_step_parsers(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("--generate-missing", "--feature", "generation.feature")
|
||||
result = pytester.runpytest("--generate-missing", "--feature", "generation.feature")
|
||||
result.assert_outcomes(passed=0, failed=0, errors=0)
|
||||
assert not result.stderr.str()
|
||||
assert result.ret == 0
|
||||
|
|
|
@ -7,12 +7,12 @@ import textwrap
|
|||
from pytest_bdd.utils import collect_dumped_objects
|
||||
|
||||
|
||||
def test_parent(testdir):
|
||||
def test_parent(pytester):
|
||||
"""Test parent given is collected.
|
||||
|
||||
Both fixtures come from the parent conftest.
|
||||
"""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
parent=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -24,7 +24,7 @@ def test_parent(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
@ -43,7 +43,7 @@ def test_parent(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -56,14 +56,14 @@ def test_parent(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_global_when_step(testdir):
|
||||
def test_global_when_step(pytester):
|
||||
"""Test when step defined in the parent conftest."""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
global_when=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -74,7 +74,7 @@ def test_global_when_step(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import when
|
||||
|
@ -87,7 +87,7 @@ def test_global_when_step(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
testdir.mkpydir("subdir").join("test_global_when.py").write(
|
||||
pytester.mkpydir("subdir").joinpath("test_global_when.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenarios
|
||||
|
@ -97,16 +97,16 @@ def test_global_when_step(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[collected_object] = collect_dumped_objects(result)
|
||||
assert collected_object == "global when step"
|
||||
|
||||
|
||||
def test_child(testdir):
|
||||
def test_child(pytester):
|
||||
"""Test the child conftest overriding the fixture."""
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
@ -125,9 +125,9 @@ def test_child(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
subdir = pytester.mkpydir("subdir")
|
||||
|
||||
subdir.join("conftest.py").write(
|
||||
subdir.joinpath("conftest.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
@ -140,7 +140,7 @@ def test_child(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
subdir.join("child.feature").write(
|
||||
subdir.joinpath("child.feature").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
Feature: Child
|
||||
|
@ -151,7 +151,7 @@ def test_child(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
subdir.join("test_library.py").write(
|
||||
subdir.joinpath("test_library.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenario
|
||||
|
@ -165,13 +165,13 @@ def test_child(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_local(testdir):
|
||||
def test_local(pytester):
|
||||
"""Test locally overridden fixtures."""
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given
|
||||
|
@ -190,9 +190,9 @@ def test_local(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
subdir = pytester.mkpydir("subdir")
|
||||
|
||||
subdir.join("local.feature").write(
|
||||
subdir.joinpath("local.feature").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
Feature: Local
|
||||
|
@ -203,7 +203,7 @@ def test_local(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
subdir.join("test_library.py").write(
|
||||
subdir.joinpath("test_library.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, scenario
|
||||
|
@ -226,18 +226,18 @@ def test_local(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_uses_correct_step_in_the_hierarchy(testdir):
|
||||
def test_uses_correct_step_in_the_hierarchy(pytester):
|
||||
"""
|
||||
Test regression found in issue #524, where we couldn't find the correct step implemntation in the
|
||||
hierarchy of files/folder as expected.
|
||||
This test uses many files and folders that act as decoy, while the real step implementation is defined
|
||||
in the last file (test_b/test_b.py).
|
||||
"""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
specific=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -249,7 +249,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import parsers, given, then
|
||||
|
@ -279,7 +279,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
# the right one is the one in test_b/test_b.py
|
||||
# We purposefully use test_a and test_c as decoys (while test_b/test_b is "good one"), so that we can test that
|
||||
# we pick the right one.
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
test_a="""\
|
||||
from pytest_bdd import given, parsers
|
||||
from pytest_bdd.utils import dump_obj
|
||||
|
@ -297,7 +297,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
dump_obj(thing + " root_test_a")
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
test_c="""\
|
||||
from pytest_bdd import given, parsers
|
||||
from pytest_bdd.utils import dump_obj
|
||||
|
@ -316,10 +316,10 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
"""
|
||||
)
|
||||
|
||||
test_b_folder = testdir.mkpydir("test_b")
|
||||
test_b_folder = pytester.mkpydir("test_b")
|
||||
|
||||
# More decoys: test_b/test_a.py and test_b/test_c.py
|
||||
test_b_folder.join("test_a.py").write(
|
||||
test_b_folder.joinpath("test_a.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, parsers
|
||||
|
@ -340,7 +340,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
test_b_folder.join("test_c.py").write(
|
||||
test_b_folder.joinpath("test_c.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import given, parsers
|
||||
|
@ -363,7 +363,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
)
|
||||
|
||||
# Finally, the file with the actual step definition that should be used
|
||||
test_b_folder.join("test_b.py").write(
|
||||
test_b_folder.joinpath("test_b.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenarios, given, parsers
|
||||
|
@ -380,7 +380,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
test_b_folder.join("test_b_alternative.py").write(
|
||||
test_b_folder.joinpath("test_b_alternative.py").write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
from pytest_bdd import scenarios, given, parsers
|
||||
|
@ -399,7 +399,7 @@ def test_uses_correct_step_in_the_hierarchy(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
[thing1, thing2] = collect_dumped_objects(result)
|
||||
|
|
|
@ -9,11 +9,11 @@ from pytest_bdd.scripts import main
|
|||
PATH = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def test_generate(testdir, monkeypatch, capsys):
|
||||
def test_generate(pytester, monkeypatch, capsys):
|
||||
"""Test if the code is generated by a given feature."""
|
||||
|
||||
features = testdir.mkdir("scripts")
|
||||
feature = features.join("generate.feature")
|
||||
features = pytester.mkdir("scripts")
|
||||
feature = features.joinpath("generate.feature")
|
||||
feature.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
|
@ -29,10 +29,9 @@ def test_generate(testdir, monkeypatch, capsys):
|
|||
"""
|
||||
),
|
||||
"utf-8",
|
||||
ensure=True,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(sys, "argv", ["", "generate", feature.strpath])
|
||||
monkeypatch.setattr(sys, "argv", ["", "generate", str(feature)])
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
assert out == textwrap.dedent(
|
||||
|
@ -79,9 +78,9 @@ def test_generate(testdir, monkeypatch, capsys):
|
|||
)
|
||||
|
||||
|
||||
def test_generate_with_quotes(testdir):
|
||||
def test_generate_with_quotes(pytester):
|
||||
"""Test that code generation escapes quote characters properly."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
generate_with_quotes=textwrap.dedent(
|
||||
'''\
|
||||
|
@ -100,7 +99,7 @@ def test_generate_with_quotes(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
result = testdir.run("pytest-bdd", "generate", "generate_with_quotes.feature")
|
||||
result = pytester.run("pytest-bdd", "generate", "generate_with_quotes.feature")
|
||||
assert result.stdout.str() == textwrap.dedent(
|
||||
'''\
|
||||
"""Handling quotes in code generation feature tests."""
|
||||
|
@ -156,13 +155,13 @@ def test_generate_with_quotes(testdir):
|
|||
)
|
||||
|
||||
|
||||
def test_unicode_characters(testdir, monkeypatch):
|
||||
def test_unicode_characters(pytester, monkeypatch):
|
||||
"""Test generating code with unicode characters.
|
||||
|
||||
Primary purpose is to ensure compatibility with Python2.
|
||||
"""
|
||||
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
unicode_characters=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -176,7 +175,7 @@ def test_unicode_characters(testdir, monkeypatch):
|
|||
),
|
||||
)
|
||||
|
||||
result = testdir.run("pytest-bdd", "generate", "unicode_characters.feature")
|
||||
result = pytester.run("pytest-bdd", "generate", "unicode_characters.feature")
|
||||
expected_output = textwrap.dedent(
|
||||
'''\
|
||||
"""Generating unicode characters feature tests."""
|
||||
|
|
|
@ -9,11 +9,11 @@ from pytest_bdd.scripts import main
|
|||
PATH = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def test_migrate(monkeypatch, capsys, testdir):
|
||||
def test_migrate(monkeypatch, capsys, pytester):
|
||||
"""Test if the code is migrated by a given file mask."""
|
||||
tests = testdir.mkpydir("tests")
|
||||
tests = pytester.mkpydir("tests")
|
||||
|
||||
tests.join("test_foo.py").write(
|
||||
tests.joinpath("test_foo.py").write_text(
|
||||
textwrap.dedent(
|
||||
'''
|
||||
"""Foo bar tests."""
|
||||
|
@ -24,7 +24,7 @@ def test_migrate(monkeypatch, capsys, testdir):
|
|||
)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(sys, "argv", ["", "migrate", tests.strpath])
|
||||
monkeypatch.setattr(sys, "argv", ["", "migrate", str(tests)])
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
out = "\n".join(sorted(out.splitlines()))
|
||||
|
@ -32,13 +32,13 @@ def test_migrate(monkeypatch, capsys, testdir):
|
|||
"""
|
||||
migrated: {0}/test_foo.py
|
||||
skipped: {0}/__init__.py""".format(
|
||||
tests.strpath
|
||||
str(tests)
|
||||
)[
|
||||
1:
|
||||
]
|
||||
)
|
||||
assert out == expected
|
||||
assert tests.join("test_foo.py").read() == textwrap.dedent(
|
||||
assert tests.joinpath("test_foo.py").read_text() == textwrap.dedent(
|
||||
'''
|
||||
"""Foo bar tests."""
|
||||
from pytest_bdd import scenario
|
||||
|
|
|
@ -30,8 +30,8 @@ def test_given_when_then_delegate_to_step(step_fn: Callable[..., Any], step_type
|
|||
)
|
||||
|
||||
|
||||
def test_step_function_multiple_target_fixtures(testdir):
|
||||
testdir.makefile(
|
||||
def test_step_function_multiple_target_fixtures(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
target_fixture=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -44,7 +44,7 @@ def test_step_function_multiple_target_fixtures(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -70,7 +70,7 @@ def test_step_function_multiple_target_fixtures(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[foo, bar] = collect_dumped_objects(result)
|
||||
|
@ -78,8 +78,8 @@ def test_step_function_multiple_target_fixtures(testdir):
|
|||
assert bar == "test bar"
|
||||
|
||||
|
||||
def test_step_functions_same_parser(testdir):
|
||||
testdir.makefile(
|
||||
def test_step_functions_same_parser(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
target_fixture=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -92,7 +92,7 @@ def test_step_functions_same_parser(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -118,7 +118,7 @@ def test_step_functions_same_parser(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[first_given, second_given] = collect_dumped_objects(result)
|
||||
|
@ -126,9 +126,9 @@ def test_step_functions_same_parser(testdir):
|
|||
assert second_given == ("re", "testfoo")
|
||||
|
||||
|
||||
def test_user_implements_a_step_generator(testdir):
|
||||
def test_user_implements_a_step_generator(pytester):
|
||||
"""Test advanced use cases, like the implementation of custom step generators."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
user_step_generator=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -142,7 +142,7 @@ def test_user_implements_a_step_generator(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import re
|
||||
|
@ -266,7 +266,7 @@ def test_user_implements_a_step_generator(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
[given, pay, assert_] = collect_dumped_objects(result)
|
||||
|
@ -275,9 +275,9 @@ def test_user_implements_a_step_generator(testdir):
|
|||
assert assert_ == "assert 9 EUR"
|
||||
|
||||
|
||||
def test_step_catches_all(testdir):
|
||||
def test_step_catches_all(pytester):
|
||||
"""Test that the @step(...) decorator works for all kind of steps."""
|
||||
testdir.makefile(
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
step_catches_all=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -292,7 +292,7 @@ def test_step_catches_all(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -311,7 +311,7 @@ def test_step_catches_all(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
objects = collect_dumped_objects(result)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_given_injection(testdir):
|
||||
testdir.makefile(
|
||||
def test_given_injection(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
given=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -14,7 +14,7 @@ def test_given_injection(testdir):
|
|||
"""
|
||||
),
|
||||
)
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -36,5 +36,5 @@ def test_given_injection(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_steps_in_feature_file_have_unicode(testdir):
|
||||
testdir.makefile(
|
||||
def test_steps_in_feature_file_have_unicode(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
unicode=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -21,7 +21,7 @@ def test_steps_in_feature_file_have_unicode(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import sys
|
||||
|
@ -51,12 +51,12 @@ def test_steps_in_feature_file_have_unicode(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
|
||||
def test_steps_in_py_file_have_unicode(testdir):
|
||||
testdir.makefile(
|
||||
def test_steps_in_py_file_have_unicode(pytester):
|
||||
pytester.makefile(
|
||||
".feature",
|
||||
unicode=textwrap.dedent(
|
||||
"""\
|
||||
|
@ -69,7 +69,7 @@ def test_steps_in_py_file_have_unicode(testdir):
|
|||
),
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
import pytest
|
||||
|
@ -95,5 +95,5 @@ def test_steps_in_py_file_have_unicode(testdir):
|
|||
"""
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import textwrap
|
||||
|
||||
|
||||
def test_hooks(testdir):
|
||||
testdir.makeconftest("")
|
||||
def test_hooks(pytester):
|
||||
pytester.makeconftest("")
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
subdir.join("conftest.py").write(
|
||||
subdir = pytester.mkpydir("subdir")
|
||||
subdir.joinpath("conftest.py").write_text(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
def pytest_pyfunc_call(pyfuncitem):
|
||||
|
@ -17,7 +17,7 @@ def test_hooks(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
subdir.join("test_foo.py").write(
|
||||
subdir.joinpath("test_foo.py").write_text(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
from pytest_bdd import scenario
|
||||
|
@ -29,7 +29,7 @@ def test_hooks(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
subdir.join("foo.feature").write(
|
||||
subdir.joinpath("foo.feature").write_text(
|
||||
textwrap.dedent(
|
||||
r"""
|
||||
Feature: The feature
|
||||
|
@ -38,15 +38,15 @@ def test_hooks(testdir):
|
|||
)
|
||||
)
|
||||
|
||||
result = testdir.runpytest("-s")
|
||||
result = pytester.runpytest("-s")
|
||||
|
||||
assert result.stdout.lines.count("pytest_pyfunc_call hook") == 1
|
||||
assert result.stdout.lines.count("pytest_generate_tests hook") == 1
|
||||
|
||||
|
||||
def test_item_collection_does_not_break_on_non_function_items(testdir):
|
||||
def test_item_collection_does_not_break_on_non_function_items(pytester):
|
||||
"""Regression test for https://github.com/pytest-dev/pytest-bdd/issues/317"""
|
||||
testdir.makeconftest(
|
||||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
|
@ -65,12 +65,12 @@ def test_item_collection_does_not_break_on_non_function_items(testdir):
|
|||
"""
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
def test_convert_me_to_custom_item_and_assert_true():
|
||||
assert False
|
||||
"""
|
||||
)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(passed=1)
|
||||
|
|
Loading…
Reference in New Issue