Skip to content

Commit 69bc737

Browse files
committed
Check for warnings and their output during unit tests
1 parent c564938 commit 69bc737

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

test_pytest_rerunfailures.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ def temporary_failure(count=1):
1919

2020

2121
def assert_outcomes(result, passed=1, skipped=0, failed=0, error=0, xfailed=0,
22-
xpassed=0, rerun=0):
22+
xpassed=0, rerun=0, warning=0):
2323
outcomes = result.parseoutcomes()
2424
assert outcomes.get('passed', 0) == passed
2525
assert outcomes.get('skipped', 0) == skipped
2626
assert outcomes.get('failed', 0) == failed
2727
assert outcomes.get('xfailed', 0) == xfailed
2828
assert outcomes.get('xpassed', 0) == xpassed
2929
assert outcomes.get('rerun', 0) == rerun
30+
assert outcomes.get('warning', 0) == warning
3031

3132

3233
def test_error_when_run_with_pdb(testdir):
@@ -237,13 +238,17 @@ def test_fail():
237238
result = testdir.runpytest('--reruns', '3',
238239
'--reruns-delay', str(delay_time))
239240

241+
num_warnings = 0
240242
if delay_time < 0:
241243
delay_time = 0
244+
num_warnings = 1
242245

243246
time.sleep.assert_called_with(delay_time)
244247

245-
assert_outcomes(result, passed=0, failed=1, rerun=3)
248+
assert_outcomes(result, passed=0, failed=1, rerun=3, warning=num_warnings)
246249

250+
if num_warnings:
251+
result.stdout.fnmatch_lines('*UserWarning: Delay time between re-runs cannot be < 0. Using default value: 0')
247252

248253
@pytest.mark.parametrize('delay_time', [-1, 0, 0.0, 1, 2.5])
249254
def test_reruns_with_delay_marker(testdir, delay_time):
@@ -258,13 +263,17 @@ def test_fail_two():
258263

259264
result = testdir.runpytest()
260265

266+
num_warnings = 0
261267
if delay_time < 0:
262268
delay_time = 0
269+
num_warnings = 1
263270

264271
time.sleep.assert_called_with(delay_time)
265272

266-
assert_outcomes(result, passed=0, failed=1, rerun=2)
273+
assert_outcomes(result, passed=0, failed=1, rerun=2, warning=num_warnings)
267274

275+
if num_warnings:
276+
result.stdout.fnmatch_lines('*UserWarning: Delay time between re-runs cannot be < 0. Using default value: 0')
268277

269278
def test_rerun_on_setup_class_with_error_with_reruns(testdir):
270279
"""

0 commit comments

Comments
 (0)