summaryrefslogtreecommitdiff
path: root/tests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py17
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.