diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-03-11 19:09:04 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-03-11 19:09:04 -0500 |
commit | ebbf3d5d59aaf638f7650db848c6583cafda8315 (patch) | |
tree | 5f7e5adc363972ace412bfa91ab3ae46abb8b9ad /tests/helpers.py | |
parent | 1bdcc691f5127edf9f197f8b509a2eeff51edcd6 (diff) | |
download | python-coveragepy-git-ebbf3d5d59aaf638f7650db848c6583cafda8315.tar.gz |
refactor: our own change_dir context manager
We don't need to use the one from unittest_mixins.
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index a96b793e..195fefde 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -4,6 +4,7 @@ """Helpers for coverage.py tests.""" import collections +import contextlib import glob import os import re @@ -207,6 +208,22 @@ def arcs_to_arcz_repr(arcs): return "\n".join(repr_list) + "\n" +@contextlib.contextmanager +def change_dir(new_dir): + """Change directory, and then change back. + + Use as a context manager, it will return to the original + directory at the end of the block. + + """ + old_dir = os.getcwd() + os.chdir(new_dir) + try: + yield + finally: + os.chdir(old_dir) + + def without_module(using_module, missing_module_name): """ Hide a module for testing. |