From 9c358656fbebc933eefd5b7ca239ef32f1f4c0da Mon Sep 17 00:00:00 2001 From: gfyoung Date: Tue, 21 Aug 2018 03:14:32 -0700 Subject: [PATCH] TST: Skip scripts test if scripts doesn't exist (#22413) If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to gh-20061. --- .../tests/scripts/test_validate_docstrings.py | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/pandas/tests/scripts/test_validate_docstrings.py b/pandas/tests/scripts/test_validate_docstrings.py index 1d35d5d30bba3..cebcbf5a61465 100644 --- a/pandas/tests/scripts/test_validate_docstrings.py +++ b/pandas/tests/scripts/test_validate_docstrings.py @@ -448,22 +448,37 @@ class TestValidator(object): @pytest.fixture(autouse=True, scope="class") def import_scripts(self): """ - Because the scripts directory is above the top level pandas package - we need to hack sys.path to know where to find that directory for - import. The below traverses up the file system to find the scripts - directory, adds to location to sys.path and imports the required - module into the global namespace before as part of class setup, - reverting those changes on teardown. + Import the validation scripts from the scripts directory. + + Because the scripts directory is above the top level pandas package, + we need to modify `sys.path` so that Python knows where to find it. + + The code below traverses up the file system to find the scripts + directory, adds the location to `sys.path`, and imports the required + module into the global namespace before as part of class setup. + + During teardown, those changes are reverted. """ + up = os.path.dirname + global_validate_one = "validate_one" file_dir = up(os.path.abspath(__file__)) - script_dir = os.path.join(up(up(up(file_dir))), 'scripts') + + script_dir = os.path.join(up(up(up(file_dir))), "scripts") sys.path.append(script_dir) - from validate_docstrings import validate_one - globals()['validate_one'] = validate_one + + try: + from validate_docstrings import validate_one + globals()[global_validate_one] = validate_one + except ImportError: + # Import will fail if the pandas installation is not inplace. + raise pytest.skip("pandas/scripts directory does not exist") + yield + + # Teardown. sys.path.pop() - del globals()['validate_one'] + del globals()[global_validate_one] def _import_path(self, klass=None, func=None): """