Skip to content

Commit

Permalink
TST: Skip scripts test if scripts doesn't exist (#22413)
Browse files Browse the repository at this point in the history
If the pandas is not inplace, the scripts directory
will not exist, and the tests will fail.

Follow-up to gh-20061.
  • Loading branch information
gfyoung authored and jreback committed Aug 21, 2018
1 parent 4f11d1a commit 9c35865
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pandas/tests/scripts/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 9c35865

Please sign in to comment.