diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/helpers.py | 17 | ||||
-rw-r--r-- | tests/test_api.py | 3 | ||||
-rw-r--r-- | tests/test_html.py | 2 | ||||
-rw-r--r-- | tests/test_xml.py | 2 |
4 files changed, 20 insertions, 4 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. diff --git a/tests/test_api.py b/tests/test_api.py index 3a5c86ac..93b14c58 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -13,7 +13,6 @@ import sys import textwrap import pytest -from unittest_mixins import change_dir import coverage from coverage import env @@ -23,7 +22,7 @@ from coverage.files import abs_file, relative_filename from coverage.misc import CoverageException from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin -from tests.helpers import assert_count_equal +from tests.helpers import assert_count_equal, change_dir class ApiTest(CoverageTest): diff --git a/tests/test_html.py b/tests/test_html.py index 1015b7d6..5b0e0345 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -14,7 +14,6 @@ import sys import mock import pytest -from unittest_mixins import change_dir import coverage from coverage.backward import unicode_class @@ -27,6 +26,7 @@ from coverage.report import get_analysis_to_report from tests.coveragetest import CoverageTest, TESTS_DIR from tests.goldtest import gold_path from tests.goldtest import compare, contains, doesnt_contain, contains_any +from tests.helpers import change_dir class HtmlTestHelpers(CoverageTest): diff --git a/tests/test_xml.py b/tests/test_xml.py index 13e015d6..94669cdc 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -10,7 +10,6 @@ import re from xml.etree import ElementTree import pytest -from unittest_mixins import change_dir import coverage from coverage.backward import import_local_file @@ -18,6 +17,7 @@ from coverage.files import abs_file from tests.coveragetest import CoverageTest from tests.goldtest import compare, gold_path +from tests.helpers import change_dir class XmlTestHelpers(CoverageTest): |