Skip to content

Commit 1e5b4ee

Browse files
committed
test/topology: Percent-encode URL in pytest artifact links
When embedding HTML documents in pytest reports with links to test artifacts, parameterized test names containing special characters like "[" and "]" can cause URL encoding issues. These characters, when used verbatim in URLs, can trigger HTTP 400 errors on web servers. This commit resolves the issue by percent-encoding the URLs for artifact links, ensuring compatibility with servers like Jenkins and preventing "HTTP ERROR 400 Illegal Path Character" errors. Changes: - Percent-encode test artifact URLs to handle special characters - Improve link robustness for parameterized test names Signed-off-by: Kefu Chai <[email protected]>
1 parent d97fbf5 commit 1e5b4ee

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/topology/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pathlib
99
import ssl
1010
import platform
11+
import urllib.parse
1112
from functools import partial
1213
from typing import List, Optional, Dict
1314
from test.pylib.random_tables import RandomTables
@@ -209,8 +210,9 @@ async def manager(request, manager_internal, record_property, build_mode):
209210
if request.config.getoption('artifacts_dir_url') is not None:
210211
# get the relative path to the tmpdir for the failed directory
211212
dir_path_relative = f"{failed_test_dir_path.as_posix()[failed_test_dir_path.as_posix().find('testlog'):]}"
212-
full_url = f"<a href={request.config.getoption('artifacts_dir_url')}/{dir_path_relative}>failed_test_logs</a>"
213-
record_property("TEST_LOGS", full_url)
213+
full_url = urllib.parse.urljoin(request.config.getoption('artifacts_dir_url'),
214+
urllib.parse.quote(dir_path_relative))
215+
record_property("TEST_LOGS", f"<a href={full_url}>failed_test_logs</a>")
214216

215217
cluster_status = await manager_client.after_test(test_case_name, not failed)
216218
await manager_client.stop() # Stop client session and close driver after each test

0 commit comments

Comments
 (0)