Skip to content

Commit

Permalink
test_aptpkg: Skip tests if /etc/apt/sources.list is missing
Browse files Browse the repository at this point in the history
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()

/<<PKGBUILDDIR>>/tests/pytests/functional/modules/test_aptpkg.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/<<PKGBUILDDIR>>/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)

/<<PKGBUILDDIR>>/tests/pytests/functional/modules/test_aptpkg.py:126:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/<<PKGBUILDDIR>>/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()

/<<PKGBUILDDIR>>/tests/pytests/functional/modules/test_aptpkg.py:169:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/<<PKGBUILDDIR>>/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 <benjamin.drung@ionos.com>
  • Loading branch information
bdrung authored and Megan Wilhite committed Apr 7, 2022
1 parent 8f64477 commit f395b52
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/pytests/functional/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pathlib
import shutil

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f395b52

Please sign in to comment.