Skip to content

Commit 98711ab

Browse files
committed
Always reset TYPESHED_HOME env var in pytype_tests.py
1 parent 0b6e42c commit 98711ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tests/pytype_test.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ def main() -> None:
4949
subdir_paths = [os.path.join(typeshed_location, d) for d in TYPESHED_SUBDIRS]
5050
check_subdirs_discoverable(subdir_paths)
5151
old_typeshed_home = os.environ.get(TYPESHED_HOME)
52-
os.environ[TYPESHED_HOME] = typeshed_location
53-
files_to_test = determine_files_to_test(paths=args.files or subdir_paths)
54-
run_all_tests(files_to_test=files_to_test, print_stderr=args.print_stderr, dry_run=args.dry_run)
55-
if old_typeshed_home is None:
56-
del os.environ[TYPESHED_HOME]
57-
else:
58-
os.environ[TYPESHED_HOME] = old_typeshed_home
52+
try:
53+
os.environ[TYPESHED_HOME] = typeshed_location
54+
files_to_test = determine_files_to_test(paths=args.files or subdir_paths)
55+
run_all_tests(files_to_test=files_to_test, print_stderr=args.print_stderr, dry_run=args.dry_run)
56+
finally:
57+
if old_typeshed_home is None:
58+
del os.environ[TYPESHED_HOME]
59+
else:
60+
os.environ[TYPESHED_HOME] = old_typeshed_home
5961

6062

6163
def create_parser() -> argparse.ArgumentParser:

0 commit comments

Comments
 (0)