From 46b126088a4a03b98ac6f5ddc0aba9acd699c1d5 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 9 Oct 2019 17:00:32 +0100 Subject: [PATCH] Temporarily change cwd when running tests that care about the cwd not being under /tmp. --- apptools/persistence/tests/test_file_path.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apptools/persistence/tests/test_file_path.py b/apptools/persistence/tests/test_file_path.py index 3c15bcfff..d70d40f97 100644 --- a/apptools/persistence/tests/test_file_path.py +++ b/apptools/persistence/tests/test_file_path.py @@ -12,16 +12,30 @@ from os.path import abspath, dirname, basename, join from io import BytesIO +# 3rd party imports. +import pkg_resources + # Enthought library imports. from apptools.persistence import state_pickler from apptools.persistence import file_path + class Test: def __init__(self): self.f = file_path.FilePath() class TestFilePath(unittest.TestCase): + def setUp(self): + # If the cwd is somewhere under /tmp, that confuses the tests below. + # Use the directory containing this file, instead. + test_cwd = pkg_resources.resource_filename("apptools.persistence", "") + self.old_cwd = os.getcwd() + os.chdir(test_cwd) + + def tearDown(self): + os.chdir(self.old_cwd) + def test_relative(self): """Test if relative paths are set correctly. """