summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-03-13 11:11:09 (GMT)
committerGitHub <noreply@github.com>2023-03-13 11:11:09 (GMT)
commit5bdcb08250d00a82f6a537ce1b7b78cd70567225 (patch)
tree05c1a783a62e92c0911f066e825ff393e623b6de
parent281078794f10a42d0aa99d660e25a434fde96ec4 (diff)
downloadcpython-5bdcb08250d00a82f6a537ce1b7b78cd70567225.zip
cpython-5bdcb08250d00a82f6a537ce1b7b78cd70567225.tar.gz
cpython-5bdcb08250d00a82f6a537ce1b7b78cd70567225.tar.bz2
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 64bde502cf89963bc7382b03ea9e1c0967d22e35) Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
-rw-r--r--Lib/test/test_zoneinfo/test_zoneinfo.py9
-rw-r--r--Misc/NEWS.d/next/Tests/2023-03-08-13-54-20.gh-issue-102537.Vfplpb.rst2
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py
index 59b35ef..e3295c6 100644
--- a/Lib/test/test_zoneinfo/test_zoneinfo.py
+++ b/Lib/test/test_zoneinfo/test_zoneinfo.py
@@ -1530,13 +1530,20 @@ class TzPathTest(TzPathUserMixin, ZoneInfoTestBase):
@contextlib.contextmanager
def python_tzpath_context(value):
path_var = "PYTHONTZPATH"
+ unset_env_sentinel = object()
+ old_env = unset_env_sentinel
try:
with OS_ENV_LOCK:
old_env = os.environ.get(path_var, None)
os.environ[path_var] = value
yield
finally:
- if old_env is None:
+ if old_env is unset_env_sentinel:
+ # In this case, `old_env` was never retrieved from the
+ # environment for whatever reason, so there's no need to
+ # reset the environment TZPATH.
+ pass
+ elif old_env is None:
del os.environ[path_var]
else:
os.environ[path_var] = old_env # pragma: nocover
diff --git a/Misc/NEWS.d/next/Tests/2023-03-08-13-54-20.gh-issue-102537.Vfplpb.rst b/Misc/NEWS.d/next/Tests/2023-03-08-13-54-20.gh-issue-102537.Vfplpb.rst
new file mode 100644
index 0000000..94d160d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2023-03-08-13-54-20.gh-issue-102537.Vfplpb.rst
@@ -0,0 +1,2 @@
+Adjust the error handling strategy in
+``test_zoneinfo.TzPathTest.python_tzpath_context``. Patch by Paul Ganssle.