-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_docstrings.py
More file actions
127 lines (97 loc) · 2.75 KB
/
Copy pathtest_docstrings.py
File metadata and controls
127 lines (97 loc) · 2.75 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""Test using docstrings as names for describe blocks"""
def test_docstrings_not_used_by_default(pytester):
pytester.makepyfile(
"""
def describe_wallet():
'''a wallet'''
def it_is_empty():
pass
"""
)
result = pytester.runpytest("-v")
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(["*::describe_wallet::it_is_empty PASSED*"])
def test_docstrings_used_as_names_when_enabled(pytester):
pytester.makeini(
"""
[pytest]
describe_docstrings = true
"""
)
pytester.makepyfile(
"""
def describe_wallet():
'''a wallet'''
def describe_when_empty():
'''when it is empty
This second line should not appear in the name.
'''
def it_has_no_balance():
pass
def describe_without_docstring():
def it_keeps_the_function_name():
pass
"""
)
result = pytester.runpytest("-v")
result.assert_outcomes(passed=2)
result.stdout.fnmatch_lines(
[
"*::a wallet::when it is empty::it_has_no_balance PASSED*",
(
"*::a wallet::describe_without_docstring"
"::it_keeps_the_function_name PASSED*"
),
]
)
def test_docstrings_used_for_shared_behaviors(pytester):
pytester.makeini(
"""
[pytest]
describe_docstrings = true
"""
)
pytester.makepyfile(
"""
from pytest import fixture
from pytest_describe import behaves_like
def a_duck():
def describe_sound():
'''the sound it makes'''
def it_quacks(sound):
assert sound == 'quack'
@behaves_like(a_duck)
def describe_something_that_quacks():
'''something that quacks'''
@fixture
def sound():
return 'quack'
"""
)
result = pytester.runpytest("-v")
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(
[
("*::something that quacks::the sound it makes::it_quacks PASSED*"),
]
)
def test_selection_by_docstring_name(pytester):
pytester.makeini(
"""
[pytest]
describe_docstrings = true
"""
)
pytester.makepyfile(
"""
def describe_wallet():
'''a wallet'''
def it_is_selected():
pass
def describe_purse():
def it_is_not_selected():
pass
"""
)
result = pytester.runpytest("-k", "wallet")
result.assert_outcomes(passed=1, deselected=1)