Skip to content

Commit 9acf605

Browse files
Prevent use before assigment in host fixture
The hostname variable will not set for all connections/backends. Currently the test does not fail as not all backends are tested.
1 parent 3e384c2 commit 9acf605

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: test/conftest.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def host(request, tmpdir_factory):
146146
fname = f"_docker_container_{spec.name}_{scope}"
147147
docker_id, docker_host, port = request.getfixturevalue(fname)
148148

149+
hostname = None
149150
if kw["connection"] == "docker":
150151
hostname = docker_id
151152
elif kw["connection"] in ("ansible", "ssh", "paramiko", "safe-ssh"):
@@ -154,7 +155,7 @@ def host(request, tmpdir_factory):
154155
key = tmpdir.join("ssh_key")
155156
with open(os.path.join(BASETESTDIR, "ssh_key")) as f:
156157
key.write(f.read())
157-
key.chmod(384) # octal 600
158+
key.chmod(0o600)
158159
if kw["connection"] == "ansible":
159160
setup_ansible_config(
160161
tmpdir, hostname, docker_host, spec.user or "root", port, str(key)
@@ -184,10 +185,10 @@ def host(request, tmpdir_factory):
184185
while not service(service_name).is_running:
185186
time.sleep(0.5)
186187

187-
if kw["connection"] != "ansible":
188-
hostspec = (spec.user or "root") + "@" + hostname
189-
else:
188+
if kw["connection"] == "ansible":
190189
hostspec = spec.name
190+
else:
191+
hostspec = f"{spec.user or 'root'}@{hostname or spec.name}"
191192

192193
b = testinfra.host.get_host(hostspec, **kw)
193194
b.backend.get_hostname = lambda: image

0 commit comments

Comments
 (0)