From f395b529d39712af9f7365fbe2d1b64152a1d917 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Wed, 16 Feb 2022 10:28:19 +0100 Subject: [PATCH] test_aptpkg: Skip tests if /etc/apt/sources.list is missing If `/etc/apt/sources.list` does not exist, three functional test cases fail with ``` FileNotFoundError: [Errno 2] No such file or directory: '/etc/apt/sources.list' ``` because they try to open this files: ``` ________________________________ test_get_repos ________________________________ def test_get_repos(): """ Test aptpkg.get_repos """ > test_repo, comps = get_current_repo() /<>/tests/pytests/functional/modules/test_aptpkg.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /<>/tests/pytests/functional/modules/test_aptpkg.py:64: in get_current_repo with salt.utils.files.fopen("/etc/apt/sources.list") as fp: ________________________ test_get_repos_multiple_comps _________________________ def test_get_repos_multiple_comps(): """ Test aptpkg.get_repos when multiple comps exist in repo. """ > test_repo, comps = get_current_repo(multiple_comps=True) /<>/tests/pytests/functional/modules/test_aptpkg.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /<>/tests/pytests/functional/modules/test_aptpkg.py:64: in get_current_repo with salt.utils.files.fopen("/etc/apt/sources.list") as fp: _____________________________ test_expand_repo_def _____________________________ def test_expand_repo_def(): """ Test aptpkg.expand_repo_def when the repo exists. """ > test_repo, comps = get_current_repo() /<>/tests/pytests/functional/modules/test_aptpkg.py:169: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /<>/tests/pytests/functional/modules/test_aptpkg.py:64: in get_current_repo with salt.utils.files.fopen("/etc/apt/sources.list") as fp: ``` Some Debian buildd do not have `/etc/apt/sources.list` and therefore these test cases fail: https://buildd.debian.org/status/fetch.php?pkg=salt&arch=all&ver=3004%2Bdfsg1-9&stamp=1644870337&raw=0 So just skip these test cases if `/etc/apt/sources.list` does not exist. Signed-off-by: Benjamin Drung --- tests/pytests/functional/modules/test_aptpkg.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/pytests/functional/modules/test_aptpkg.py b/tests/pytests/functional/modules/test_aptpkg.py index 65b8064f4557..1a98700e5e75 100644 --- a/tests/pytests/functional/modules/test_aptpkg.py +++ b/tests/pytests/functional/modules/test_aptpkg.py @@ -1,3 +1,4 @@ +import os import pathlib import shutil @@ -102,6 +103,9 @@ def test_list_repos(): assert check_repo["comps"] in check_repo["line"] +@pytest.mark.skipif( + not os.path.isfile("/etc/apt/sources.list"), reason="Missing /etc/apt/sources.list" +) def test_get_repos(): """ Test aptpkg.get_repos @@ -118,6 +122,9 @@ def test_get_repos(): assert ret["file"] == "/etc/apt/sources.list" +@pytest.mark.skipif( + not os.path.isfile("/etc/apt/sources.list"), reason="Missing /etc/apt/sources.list" +) def test_get_repos_multiple_comps(): """ Test aptpkg.get_repos when multiple comps @@ -162,6 +169,9 @@ def test_del_repo(revert_repo_file): assert "Repo {} doesn't exist".format(test_repo) in exc.value.message +@pytest.mark.skipif( + not os.path.isfile("/etc/apt/sources.list"), reason="Missing /etc/apt/sources.list" +) def test_expand_repo_def(): """ Test aptpkg.expand_repo_def when the repo exists.