Skip to content

Commit 6b1d7fc

Browse files
vitkyrkaclaude
andcommitted
velero: parametrize TestAssertPodStable in kube_discovery tests
The six TestAssertPodStable methods were one-liners exercising the same function with a different input pair and expected outcome each time — collapse them into a single parametrized test, with the stable no-raise case sitting alongside the raising ones via nullcontext. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 155a97a commit 6b1d7fc

1 file changed

Lines changed: 40 additions & 22 deletions

File tree

datadog_checks_dev/tests/test_kube_discovery.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import json
55
import os
6+
from contextlib import nullcontext
67

78
import mock
89
import pytest
@@ -367,25 +368,42 @@ def fake_run_command(command, **kwargs):
367368

368369

369370
class TestAssertPodStable:
370-
def test_detects_uid_change(self):
371-
with pytest.raises(AssertionError, match='Pod changed'):
372-
assert_pod_stable(pod_state(uid='a'), pod_state(uid='b'), 1)
373-
374-
def test_detects_not_running(self):
375-
with pytest.raises(AssertionError, match="Pod phase is 'Pending'"):
376-
assert_pod_stable(pod_state(), pod_state(phase='Pending'), 1)
377-
378-
def test_detects_restart(self):
379-
with pytest.raises(AssertionError, match='restart count changed'):
380-
assert_pod_stable(pod_state(restart_count=0), pod_state(restart_count=1), 1)
381-
382-
def test_detects_not_ready(self):
383-
with pytest.raises(AssertionError, match='is not ready'):
384-
assert_pod_stable(pod_state(), pod_state(ready=False), 1)
385-
386-
def test_detects_oom_killed(self):
387-
with pytest.raises(AssertionError, match='OOMKilled'):
388-
assert_pod_stable(pod_state(), pod_state(terminated_reason='OOMKilled'), 1)
389-
390-
def test_stable_pod_does_not_raise(self):
391-
assert_pod_stable(pod_state(), pod_state(), 1)
371+
@pytest.mark.parametrize(
372+
('initial', 'current', 'expectation'),
373+
[
374+
pytest.param(
375+
pod_state(uid='a'),
376+
pod_state(uid='b'),
377+
pytest.raises(AssertionError, match='Pod changed'),
378+
id='uid_change',
379+
),
380+
pytest.param(
381+
pod_state(),
382+
pod_state(phase='Pending'),
383+
pytest.raises(AssertionError, match="Pod phase is 'Pending'"),
384+
id='not_running',
385+
),
386+
pytest.param(
387+
pod_state(restart_count=0),
388+
pod_state(restart_count=1),
389+
pytest.raises(AssertionError, match='restart count changed'),
390+
id='restart',
391+
),
392+
pytest.param(
393+
pod_state(),
394+
pod_state(ready=False),
395+
pytest.raises(AssertionError, match='is not ready'),
396+
id='not_ready',
397+
),
398+
pytest.param(
399+
pod_state(),
400+
pod_state(terminated_reason='OOMKilled'),
401+
pytest.raises(AssertionError, match='OOMKilled'),
402+
id='oom_killed',
403+
),
404+
pytest.param(pod_state(), pod_state(), nullcontext(), id='stable'),
405+
],
406+
)
407+
def test_assert_pod_stable(self, initial, current, expectation):
408+
with expectation:
409+
assert_pod_stable(initial, current, 1)

0 commit comments

Comments
 (0)