-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathtest_given.py
More file actions
82 lines (65 loc) · 2.03 KB
/
Copy pathtest_given.py
File metadata and controls
82 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Given tests."""
from __future__ import annotations
import textwrap
def test_given_injection(pytester):
pytester.makefile(
".feature",
given=textwrap.dedent(
"""\
Feature: Given
Scenario: Test given fixture injection
Given I have injecting given
Then foo should be "injected foo"
"""
),
)
pytester.makepyfile(
textwrap.dedent(
"""\
import pytest
from pytest_bdd import given, then, scenario
@scenario("given.feature", "Test given fixture injection")
def test_given():
pass
@given("I have injecting given", target_fixture="foo")
def _():
return "injected foo"
@then('foo should be "injected foo"')
def _(foo):
assert foo == "injected foo"
"""
)
)
result = pytester.runpytest()
result.assert_outcomes(passed=1)
def test_given_injection_no_deprecation_warning(pytester):
"""Injecting a target fixture must not emit pytest deprecation warnings."""
pytester.makefile(
".feature",
given=textwrap.dedent(
"""\
Feature: Given
Scenario: Test given fixture injection
Given I have injecting given
Then foo should be "injected foo"
"""
),
)
pytester.makepyfile(
textwrap.dedent(
"""\
from pytest_bdd import given, then, scenario
@scenario("given.feature", "Test given fixture injection")
def test_given():
pass
@given("I have injecting given", target_fixture="foo")
def _():
return "injected foo"
@then('foo should be "injected foo"')
def _(foo):
assert foo == "injected foo"
"""
)
)
result = pytester.runpytest("-W", "error::DeprecationWarning", "-W", "error::PendingDeprecationWarning")
result.assert_outcomes(passed=1)