Skip to content
Merged
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
16 changes: 13 additions & 3 deletions tools/azure-sdk-tools/devtools_testutils/proxy_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ def get_recording_id():
def get_test_id():
# type: () -> str
# pytest sets the current running test in an environment variable
# the path to the test can depend on the environment, so we can't assume this is the path from the repo root
setting_value = os.getenv("PYTEST_CURRENT_TEST")

path_to_test = os.path.normpath(setting_value.split(" ")[0])
path_components = path_to_test.split(os.sep)

full_path_to_test = os.path.abspath(path_to_test)

# walk up to the repo root by looking for "sdk" directory or root of file system
path_components = []
head, tail = os.path.split(full_path_to_test)
while tail != "sdk" and tail != "":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you have any other stop cases here. Famous last words 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing a while loop always terrifies me, but I'm also pretty sure this should be good. Knocking furiously on wood

path_components.append(tail)
head, tail = os.path.split(head)

# reverse path_components to construct components of path from repo root: [sdk, ..., tests, {test}]
path_components.append("sdk")
path_components.reverse()
for idx, val in enumerate(path_components):
if val.startswith("test"):
path_components.insert(idx + 1, "recordings")
Expand Down