Skip to content

Commit 63a33f0

Browse files
committed
convert to warn instead of warnings so conftest and __init__ messages are captured even though they are prior to individual tests
1 parent 86b787e commit 63a33f0

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

mlos_bench/mlos_bench/tests/__init__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import stat
1616
import sys
1717
from datetime import tzinfo
18-
from logging import warning
18+
from warnings import warn
1919
from subprocess import run
2020

2121
import pytest
@@ -62,16 +62,16 @@
6262
uid = st.st_uid
6363
gid = st.st_gid
6464
except Exception as e: # pylint: disable=broad-except
65-
warning(f"Could not stat {DOCKER_SOCK_PATH}: {e}")
65+
warn(f"Could not stat {DOCKER_SOCK_PATH}: {e}", UserWarning)
6666
try:
6767
if sys.platform != "win32":
6868
current_uid = os.getuid()
6969
current_gid = os.getgid()
7070
gids = os.getgroups()
7171
if not os.access(DOCKER_SOCK_PATH, os.W_OK):
72-
warning(f"Docker socket {DOCKER_SOCK_PATH} is not writable.")
72+
warn(f"Docker socket {DOCKER_SOCK_PATH} is not writable.", UserWarning)
7373
except Exception as e: # pylint: disable=broad-except
74-
warning(f"Could not get current user info: {e}")
74+
warn(f"Could not get current user info: {e}", UserWarning)
7575

7676
cmd = run(
7777
"docker builder inspect default || docker buildx inspect default",
@@ -85,16 +85,17 @@
8585
line for line in stdout.splitlines() if "Platform" in line and "linux" in line
8686
):
8787
DOCKER = None
88-
warning(
88+
warn(
8989
"Docker is available but missing buildx support for targeting linux platform:\n"
9090
+ f"stdout:\n{stdout}\n"
9191
+ f"stderr:\n{stderr}\n"
9292
+ f"sock_path: {DOCKER_SOCK_PATH} sock mode: {mode} sock uid: {uid} gid: {gid}\n"
93-
+ f"current_uid: {current_uid} groups: {gids}\n"
93+
+ f"current_uid: {current_uid} groups: {gids}\n",
94+
UserWarning,
9495
)
9596

9697
if not DOCKER:
97-
warning("Docker is not available on this system. Some tests will be skipped.")
98+
warn("Docker is not available on this system. Some tests will be skipped.", UserWarning)
9899

99100
# A decorator for tests that require docker.
100101
# Use with @requires_docker above a test_...() function.
@@ -107,7 +108,7 @@
107108
# Use with @requires_ssh above a test_...() function.
108109
SSH = shutil.which("ssh")
109110
if not SSH:
110-
warning("ssh is not available on this system. Some tests will be skipped.")
111+
warn("ssh is not available on this system. Some tests will be skipped.", UserWarning)
111112
requires_ssh = pytest.mark.skipif(not SSH, reason="ssh is not available on this system.")
112113

113114
# A common seed to use to avoid tracking down race conditions and intermingling
@@ -232,14 +233,16 @@ def are_dir_trees_equal(dir1: str, dir2: str) -> bool:
232233
or len(dirs_cmp.right_only) > 0
233234
or len(dirs_cmp.funny_files) > 0
234235
):
235-
warning(
236-
f"Found differences in dir trees {dir1}, {dir2}:\n"
237-
f"{dirs_cmp.diff_files}\n{dirs_cmp.funny_files}"
236+
warn(
237+
UserWarning(
238+
f"Found differences in dir trees {dir1}, {dir2}:\n"
239+
f"{dirs_cmp.diff_files}\n{dirs_cmp.funny_files}"
240+
)
238241
)
239242
return False
240243
(_, mismatch, errors) = filecmp.cmpfiles(dir1, dir2, dirs_cmp.common_files, shallow=False)
241244
if len(mismatch) > 0 or len(errors) > 0:
242-
warning(f"Found differences in files:\n{mismatch}\n{errors}")
245+
warn(f"Found differences in files:\n{mismatch}\n{errors}", UserWarning)
243246
return False
244247
for common_dir in dirs_cmp.common_dirs:
245248
new_dir1 = os.path.join(dir1, common_dir)

mlos_viz/mlos_viz/tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import sys
99
from glob import glob
10-
from logging import warning
10+
from warnings import warn
1111
from pathlib import Path
1212

1313
from mlos_bench.tests import tunable_groups_fixtures
@@ -22,8 +22,6 @@
2222
tunable_groups_config = tunable_groups_fixtures.tunable_groups_config
2323
tunable_groups = tunable_groups_fixtures.tunable_groups
2424

25-
warning("test")
26-
2725
# Workaround for #1004
2826
# See Also: https://github.com/python/cpython/issues/111754
2927
if sys.platform == "win32":
@@ -53,6 +51,8 @@
5351
)
5452
).parent
5553
)
56-
warning(f"""Setting {env_var} to {os.environ[env_var]}""")
54+
warn(f"""Setting {env_var} to {os.environ[env_var]}""", UserWarning)
5755
except StopIteration:
58-
warning(f"{env_var} not found, some Tcl/Tk functionality may be limited.")
56+
warn(
57+
UserWarning(f"{env_var} not found, some Tcl/Tk functionality may be limited.")
58+
)

0 commit comments

Comments
 (0)