|
15 | 15 | import stat |
16 | 16 | import sys |
17 | 17 | from datetime import tzinfo |
18 | | -from logging import warning |
| 18 | +from warnings import warn |
19 | 19 | from subprocess import run |
20 | 20 |
|
21 | 21 | import pytest |
|
62 | 62 | uid = st.st_uid |
63 | 63 | gid = st.st_gid |
64 | 64 | 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) |
66 | 66 | try: |
67 | 67 | if sys.platform != "win32": |
68 | 68 | current_uid = os.getuid() |
69 | 69 | current_gid = os.getgid() |
70 | 70 | gids = os.getgroups() |
71 | 71 | 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) |
73 | 73 | 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) |
75 | 75 |
|
76 | 76 | cmd = run( |
77 | 77 | "docker builder inspect default || docker buildx inspect default", |
|
85 | 85 | line for line in stdout.splitlines() if "Platform" in line and "linux" in line |
86 | 86 | ): |
87 | 87 | DOCKER = None |
88 | | - warning( |
| 88 | + warn( |
89 | 89 | "Docker is available but missing buildx support for targeting linux platform:\n" |
90 | 90 | + f"stdout:\n{stdout}\n" |
91 | 91 | + f"stderr:\n{stderr}\n" |
92 | 92 | + 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, |
94 | 95 | ) |
95 | 96 |
|
96 | 97 | 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) |
98 | 99 |
|
99 | 100 | # A decorator for tests that require docker. |
100 | 101 | # Use with @requires_docker above a test_...() function. |
|
107 | 108 | # Use with @requires_ssh above a test_...() function. |
108 | 109 | SSH = shutil.which("ssh") |
109 | 110 | 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) |
111 | 112 | requires_ssh = pytest.mark.skipif(not SSH, reason="ssh is not available on this system.") |
112 | 113 |
|
113 | 114 | # 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: |
232 | 233 | or len(dirs_cmp.right_only) > 0 |
233 | 234 | or len(dirs_cmp.funny_files) > 0 |
234 | 235 | ): |
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 | + ) |
238 | 241 | ) |
239 | 242 | return False |
240 | 243 | (_, mismatch, errors) = filecmp.cmpfiles(dir1, dir2, dirs_cmp.common_files, shallow=False) |
241 | 244 | 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) |
243 | 246 | return False |
244 | 247 | for common_dir in dirs_cmp.common_dirs: |
245 | 248 | new_dir1 = os.path.join(dir1, common_dir) |
|
0 commit comments