Skip to content

Commit

Permalink
Make it easier to add new envfile tests
Browse files Browse the repository at this point in the history
We have 2 tests using the valid yaml. Both test need to create fake
addons directories in a temporary directory. This makes it harder than
needed to create new tests.

Change the valid_yaml to pytest fixture returning an Env namedtuple with
an open file object with the valid yaml and the path of the addons
directory created by the fixture. With this creating new test requires
one line to create an env.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jul 15, 2023
1 parent 9468d1a commit ce6918d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/drenv/envfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

import io
import pytest
from collections import namedtuple

from . import envfile

valid_yaml = """
Env = namedtuple("Env", "file,addons_root")


@pytest.fixture
def valid_env(tmpdir):
yaml = """
name: test
templates:
Expand Down Expand Up @@ -57,17 +64,14 @@
args: []
"""


def create_addons(tmpdir):
for i in range(1, 7):
tmpdir.mkdir(f"addon{i}")

return Env(file=io.StringIO(yaml), addons_root=str(tmpdir))


def test_valid(tmpdir):
create_addons(tmpdir)
f = io.StringIO(valid_yaml)
env = envfile.load(f, addons_root=str(tmpdir))
def test_valid(valid_env):
env = envfile.load(valid_env.file, addons_root=valid_env.addons_root)

# profile dr1

Expand Down Expand Up @@ -122,10 +126,12 @@ def test_valid(tmpdir):
assert worker["addons"][0]["args"] == []


def test_name_prefix(tmpdir):
create_addons(tmpdir)
f = io.StringIO(valid_yaml)
env = envfile.load(f, name_prefix="prefix-", addons_root=str(tmpdir))
def test_name_prefix(valid_env):
env = envfile.load(
valid_env.file,
name_prefix="prefix-",
addons_root=valid_env.addons_root,
)

# env

Expand Down

0 comments on commit ce6918d

Please sign in to comment.