Skip to content

Commit

Permalink
chore: remove __init__ from pytest test class (canonical#5856)
Browse files Browse the repository at this point in the history
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
  • Loading branch information
aciba90 authored and mathmarchand committed Nov 21, 2024
1 parent 023df12 commit 1c8ae67
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions tests/unittests/distros/package_management/test_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,41 +119,43 @@ def test_search_stem(self, m_subp, m_which, mocker):
)


@mock.patch.object(
apt,
"APT_LOCK_FILES",
[f"{TMP_DIR}/{FILE}" for FILE in apt.APT_LOCK_FILES],
)
class TestUpdatePackageSources:
def __init__(self):
MockPaths = get_mock_paths(TMP_DIR)
self.MockPaths = MockPaths({}, FakeDataSource())
@pytest.fixture(scope="function")
def apt_paths(tmpdir):
MockPaths = get_mock_paths(str(tmpdir))
with mock.patch.object(
apt,
"APT_LOCK_FILES",
[f"{tmpdir}/{FILE}" for FILE in apt.APT_LOCK_FILES],
):
yield MockPaths({}, FakeDataSource())


class TestUpdatePackageSources:
@mock.patch.object(apt.subp, "which", return_value=True)
@mock.patch.object(apt.subp, "subp")
def test_force_update_calls_twice(self, m_subp, m_which):
def test_force_update_calls_twice(self, m_subp, m_which, apt_paths):
"""Ensure that force=true calls apt update again"""
instance = apt.Apt(helpers.Runners(self.MockPaths))
instance = apt.Apt(helpers.Runners(apt_paths))
instance.update_package_sources()
instance.update_package_sources(force=True)
assert 2 == len(m_subp.call_args_list)
TMP_DIR.cleanup()

@mock.patch.object(apt.subp, "which", return_value=True)
@mock.patch.object(apt.subp, "subp")
def test_force_update_twice_calls_twice(self, m_subp, m_which):
def test_force_update_twice_calls_twice(self, m_subp, m_which, apt_paths):
"""Ensure that force=true calls apt update again when called twice"""
instance = apt.Apt(helpers.Runners(self.MockPaths))
instance = apt.Apt(helpers.Runners(apt_paths))
instance.update_package_sources(force=True)
instance.update_package_sources(force=True)
assert 2 == len(m_subp.call_args_list)
TMP_DIR.cleanup()

@mock.patch.object(apt.subp, "which", return_value=True)
@mock.patch.object(apt.subp, "subp")
def test_no_force_update_calls_once(self, m_subp, m_which):
def test_no_force_update_calls_once(self, m_subp, m_which, apt_paths):
"""Ensure that apt-get update calls are deduped unless expected"""
instance = apt.Apt(helpers.Runners(self.MockPaths))
instance = apt.Apt(helpers.Runners(apt_paths))
instance.update_package_sources()
instance.update_package_sources()
assert 1 == len(m_subp.call_args_list)
Expand Down

0 comments on commit 1c8ae67

Please sign in to comment.