FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tests: Use class-scoped fixtures · exkson/ceph-devstack@8aae98e · GitHub

Repository navigation

Commit 8aae98e

Browse files
committed
tests: Use class-scoped fixtures
Signed-off-by: Zack Cerza <zack@redhat.com>
1 parent ac3b6b8 commit 8aae98e

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

‎ceph_devstack/resources/test/test_container.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010

1111

1212
class TestContainer(_TestPodmanResource):
13-
apply_actions = ["build", "create", "start", "stop", "remove"]
14-
15-
@pytest.fixture
13+
@pytest.fixture(scope="class")
1614
def cls(self):
1715
return Container
1816

17+
@pytest.fixture(
18+
scope="class", params=["build", "create", "start", "stop", "remove"]
19+
)
20+
def action(self, request):
21+
return request.param
22+
1923
@pytest.mark.parametrize("rc,res", ([0, True], [1, False]))
2024
async def test_exists_yes(self, cls, rc, res):
2125
with patch.object(cls, "cmd"):
@@ -51,7 +55,6 @@ async def test_is_running_no_bc_dne(self, cls):
5155
obj.cmd.return_value = AsyncMock(returncode=1)
5256
assert await obj.is_running() is False
5357

54-
@pytest.mark.parametrize("action", apply_actions)
5558
async def test_empty_cmd_skips_action(self, cls, action):
5659
with patch.object(cls, "cmd"):
5760
obj = cls()

‎ceph_devstack/resources/test/test_podmanresource.py‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77

88
class TestPodmanResource:
9-
apply_actions = ["create", "remove"]
10-
11-
@pytest.fixture
9+
@pytest.fixture(scope="class")
1210
def cls(self):
1311
return PodmanResource
1412

13+
@pytest.fixture(scope="class", params=["create", "remove"])
14+
def action(self, request):
15+
return request.param
16+
1517
def test_name(self, cls):
1618
obj = cls()
1719
assert obj.name == cls.__name__.lower()
@@ -31,13 +33,12 @@ def test_repr(self, cls):
3133
obj = cls(name="foo")
3234
assert repr(obj) == f'{class_name}(name="foo")'
3335

34-
async def test_apply(self, cls):
35-
for action in self.apply_actions:
36-
with patch.object(cls, action):
37-
obj = cls()
38-
await obj.apply(action)
39-
method = getattr(obj, action)
40-
method.assert_awaited_once()
36+
async def test_apply(self, cls, action):
37+
with patch.object(cls, action):
38+
obj = cls()
39+
await obj.apply(action)
40+
method = getattr(obj, action)
41+
method.assert_awaited_once()
4142

4243
async def test_cmd(self, cls):
4344
with patch("ceph_devstack.resources.async_cmd") as m_async_cmd:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL