[diffoscope] 01/01: contextlib.contextmanager yields need to be wrapped in a try-finally block
Ximin Luo
infinity0 at debian.org
Mon May 29 20:29:06 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch experimental
in repository diffoscope.
commit 40c31ad79e95f8c47f162910bc542bd9be7f9c6b
Author: Ximin Luo <infinity0 at debian.org>
Date: Mon May 29 22:28:29 2017 +0200
contextlib.contextmanager yields need to be wrapped in a try-finally block
---
tests/utils/data.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/tests/utils/data.py b/tests/utils/data.py
index dc43f0d..b2d7e06 100644
--- a/tests/utils/data.py
+++ b/tests/utils/data.py
@@ -50,16 +50,18 @@ def get_data(filename):
return f.read()
+# https://code.activestate.com/recipes/576620-changedirectory-context-manager/#c3
@contextlib.contextmanager
def cwd_data():
"""A context manager which changes the working directory to the given
path, and then changes it back to its previous value on exit.
-
"""
prev_cwd = os.getcwd()
os.chdir(data(""))
- yield
- os.chdir(prev_cwd)
+ try:
+ yield
+ finally:
+ os.chdir(prev_cwd)
def load_fixture(filename):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list