Skip to content

Commit 96f8ba6

Browse files
committed
test: replace ventored chdir context manager with contextlib
Our docker container uses Python 3.12 these days, so follow the comment the says "once we upgrade past 3.11, use the stdlib". Signed-off-by: Patrick Roy <[email protected]>
1 parent 45cca69 commit 96f8ba6

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

tests/framework/ab_test.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
of both invocations is the same, the test passes (with us being alerted to this situtation via a special pipeline that
2222
does not block PRs). If not, it fails, preventing PRs from introducing new vulnerable dependencies.
2323
"""
24-
import contextlib
2524
import os
2625
import statistics
2726
from pathlib import Path
@@ -267,17 +266,3 @@ def git_clone(clone_path, commitish):
267266
utils.check_output(f"git clone -b {branch_name} {git_root.strip()} {clone_path}")
268267
utils.check_output(f"git branch -D {branch_name}")
269268
return clone_path
270-
271-
272-
# Once we upgrade to python 3.11, this will be in contextlib:
273-
# https://docs.python.org/3/library/contextlib.html#contextlib.chdir
274-
@contextlib.contextmanager
275-
def chdir(to):
276-
"""Context manager that temporarily `chdir`s to the specified path"""
277-
cur = os.getcwd()
278-
279-
try:
280-
os.chdir(to)
281-
yield
282-
finally:
283-
os.chdir(cur)

tests/integration_tests/performance/test_benchmarks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Optional benchmarks-do-not-regress test"""
4+
import contextlib
45
import json
56
import logging
67
import platform
@@ -10,7 +11,7 @@
1011
import pytest
1112

1213
from framework import utils
13-
from framework.ab_test import chdir, git_ab_test
14+
from framework.ab_test import git_ab_test
1415
from host_tools.cargo_build import cargo
1516

1617
LOGGER = logging.getLogger(__name__)
@@ -32,7 +33,7 @@ def run_criterion(firecracker_checkout: Path, is_a: bool) -> Path:
3233
"""
3334
baseline_name = "a_baseline" if is_a else "b_baseline"
3435

35-
with chdir(firecracker_checkout):
36+
with contextlib.chdir(firecracker_checkout):
3637
# Passing --message-format json to cargo tells it to print its log in a json format. At the end, instead of the
3738
# usual "placed executable <...> at <...>" we'll get a json object with an 'executable' key, from which we
3839
# extract the path to the compiled benchmark binary.

0 commit comments

Comments
 (0)