Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests when HOSTNAME is set, but empty string #1618

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1616.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix tests when the ``HOSTNAME`` environment variable is set, but empty string - by :user:`hroncok`
29 changes: 10 additions & 19 deletions tests/unit/test_result.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import os
import signal
import socket
Expand All @@ -18,22 +19,12 @@ def create_fake_pkg(tmpdir):


@pytest.fixture()
def no_hostname_envvar():
hostname = os.getenv("HOSTNAME")
if hostname:
del os.environ["HOSTNAME"]
try:
yield
finally:
try:
del os.environ["HOSTNAME"]
except KeyError:
pass
if hostname:
os.environ["HOSTNAME"] = hostname


def test_pre_set_header(no_hostname_envvar):
def clean_hostname_envvar(monkeypatch):
monkeypatch.delenv("HOSTNAME", raising=False)
return functools.partial(monkeypatch.setenv, "HOSTNAME")


def test_pre_set_header(clean_hostname_envvar):
replog = ResultLog()
d = replog.dict
assert replog.dict == d
Expand All @@ -46,7 +37,7 @@ def test_pre_set_header(no_hostname_envvar):
assert replog2.dict == replog.dict


def test_set_header(pkg, no_hostname_envvar):
def test_set_header(pkg, clean_hostname_envvar):
replog = ResultLog()
d = replog.dict
assert replog.dict == d
Expand All @@ -64,8 +55,8 @@ def test_set_header(pkg, no_hostname_envvar):
assert replog2.dict == replog.dict


def test_hosname_via_envvar(no_hostname_envvar):
os.environ["HOSTNAME"] = "toxicity"
def test_hosname_via_envvar(clean_hostname_envvar):
clean_hostname_envvar("toxicity")
replog = ResultLog()
assert replog.dict["host"] == "toxicity"

Expand Down