Skip to content

Commit cd063ba

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Update test_readme.py to use more precise error match strings for
ValueError cases
1 parent 55ec18d commit cd063ba

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

tests/documentation/test_readme.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,14 @@ def test_p99_cached(self) -> None:
151151

152152
class TestScenarioConstructorValidation:
153153
def test_number_zero_raises(self) -> None:
154-
# README: "passing 0 or a negative value raises ValueError"
155-
with pytest.raises(ValueError):
154+
with pytest.raises(ValueError, match='number'):
156155
Scenario(lambda: None, name='s', number=0)
157156

158157
def test_number_negative_raises(self) -> None:
159-
with pytest.raises(ValueError):
158+
with pytest.raises(ValueError, match='number'):
160159
Scenario(lambda: None, name='s', number=-1)
161160

162161
def test_args_none_and_empty_list_equivalent(self) -> None:
163-
# README: "None (the default) and [] both mean the function is called with no arguments"
164162
calls_none: list[tuple[object, ...]] = []
165163
calls_empty: list[tuple[object, ...]] = []
166164

@@ -176,20 +174,18 @@ def fn_empty(*a: object) -> None:
176174
assert calls_empty == [()]
177175

178176
def test_args_shallow_copied(self) -> None:
179-
# README: "The list is shallow-copied on construction"
180-
original = [1, 2]
181-
s = Scenario(lambda *_: None, args=original, name='s', number=1)
182-
original.append(3)
183177
call_log: list[tuple[object, ...]] = []
184178

185179
def fn(*a: object) -> None:
186180
call_log.append(a)
187181

188-
Scenario(fn, args=[1, 2], name='s', number=1).run()
182+
original = [1, 2]
183+
s = Scenario(fn, args=original, name='s', number=1)
184+
original.append(3)
185+
s.run()
189186
assert call_log == [(1, 2)] # mutation after construction has no effect
190187

191188
def test_custom_timer(self) -> None:
192-
# README: "Supply a custom clock to get deterministic measurements in tests"
193189
tick = [0.0]
194190

195191
def fake_timer() -> float:
@@ -203,14 +199,13 @@ def fake_timer() -> float:
203199

204200
class TestPercentileValidation:
205201
def test_percentile_zero_raises(self) -> None:
206-
# README: "passing 0 or a value above 100 raises ValueError"
207202
result = Scenario(lambda: None, name='noop', number=10).run()
208-
with pytest.raises(ValueError):
203+
with pytest.raises(ValueError, match='percentile'):
209204
result.percentile(0)
210205

211206
def test_percentile_above_100_raises(self) -> None:
212207
result = Scenario(lambda: None, name='noop', number=10).run()
213-
with pytest.raises(ValueError):
208+
with pytest.raises(ValueError, match='percentile'):
214209
result.percentile(101)
215210

216211

0 commit comments

Comments
 (0)