Skip to content

Commit 84f587e

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Add test for max_mean failure when only one scenario exceeds threshold
1 parent e53b447 commit 84f587e

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/cli/test_scenario_group_cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def test_max_mean_and_number_combined(self) -> None:
9494
assert 'benchmark: first' in proc.stdout
9595
assert 'benchmark: second' in proc.stdout
9696

97+
def test_max_mean_fails_when_only_one_exceeds(self) -> None:
98+
# slow mean≈1.0, fast mean≈0.001; threshold=0.5 → only slow exceeds → exit 1
99+
proc = run_script(mixed_speed_group_script(), '--max-mean', '0.5')
100+
assert proc.returncode == 1
101+
# both results are still printed (no early exit)
102+
assert 'benchmark: slow' in proc.stdout
103+
assert 'benchmark: fast' in proc.stdout
104+
97105

98106
class TestScenarioGroupCliHelp:
99107
def test_help_exits_0(self) -> None:
@@ -137,6 +145,30 @@ def test_empty_group_no_output(self) -> None:
137145
assert proc.stderr == ''
138146

139147

148+
def mixed_speed_group_script() -> str:
149+
"""Two scenarios with different speeds: slow (mean≈1.0s) and fast (mean≈0.001s)."""
150+
return textwrap.dedent(f'''
151+
import sys
152+
sys.path.insert(0, {str(__import__('pathlib').Path(__file__).parent.parent.parent)!r})
153+
from microbenchmark import Scenario, ScenarioGroup
154+
155+
slow_tick = [0.0]
156+
def slow_timer():
157+
slow_tick[0] += 1.0
158+
return slow_tick[0]
159+
160+
fast_tick = [0.0]
161+
def fast_timer():
162+
fast_tick[0] += 0.001
163+
return fast_tick[0]
164+
165+
s1 = Scenario(lambda: None, name='slow', number=5, timer=slow_timer)
166+
s2 = Scenario(lambda: None, name='fast', number=5, timer=fast_timer)
167+
group = s1 + s2
168+
group.cli()
169+
''')
170+
171+
140172
def single_scenario_script() -> str:
141173
return textwrap.dedent(f'''
142174
import sys

0 commit comments

Comments
 (0)