Skip to content

Commit 5bdcb08

Browse files
GH-102537: Handle check for PYTHONTZPATH failing in zoneinfo test (GH-102538)
It is possible but unlikely for the `python_tzpath_context` function to fail between the start of the `try` block and the point where `os.environ.get` succeeds, in which case `old_env` will be undefined. In this case, we want to take no action. Practically speaking this will really only happen in an error condition anyway, so it doesn't really matter, but we should probably do it right anyway. (cherry picked from commit 64bde50) Co-authored-by: Paul Ganssle <[email protected]>
1 parent 2810787 commit 5bdcb08

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/test/test_zoneinfo/test_zoneinfo.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,20 @@ class TzPathTest(TzPathUserMixin, ZoneInfoTestBase):
15301530
@contextlib.contextmanager
15311531
def python_tzpath_context(value):
15321532
path_var = "PYTHONTZPATH"
1533+
unset_env_sentinel = object()
1534+
old_env = unset_env_sentinel
15331535
try:
15341536
with OS_ENV_LOCK:
15351537
old_env = os.environ.get(path_var, None)
15361538
os.environ[path_var] = value
15371539
yield
15381540
finally:
1539-
if old_env is None:
1541+
if old_env is unset_env_sentinel:
1542+
# In this case, `old_env` was never retrieved from the
1543+
# environment for whatever reason, so there's no need to
1544+
# reset the environment TZPATH.
1545+
pass
1546+
elif old_env is None:
15401547
del os.environ[path_var]
15411548
else:
15421549
os.environ[path_var] = old_env # pragma: nocover
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Adjust the error handling strategy in
2+
``test_zoneinfo.TzPathTest.python_tzpath_context``. Patch by Paul Ganssle.

0 commit comments

Comments
 (0)