Skip to content

Commit 96ec3d7

Browse files
committed
TST: Skip scripts test if scripts doesn't exist
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to gh-20061.
1 parent 4f11d1a commit 96ec3d7

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

pandas/tests/scripts/test_validate_docstrings.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,37 @@ class TestValidator(object):
448448
@pytest.fixture(autouse=True, scope="class")
449449
def import_scripts(self):
450450
"""
451-
Because the scripts directory is above the top level pandas package
452-
we need to hack sys.path to know where to find that directory for
453-
import. The below traverses up the file system to find the scripts
454-
directory, adds to location to sys.path and imports the required
455-
module into the global namespace before as part of class setup,
456-
reverting those changes on teardown.
451+
Import the validation scripts from the scripts directory.
452+
453+
Because the scripts directory is above the top level pandas package,
454+
we need to modify `sys.path` so that Python knows where to find it.
455+
456+
The code below traverses up the file system to find the scripts
457+
directory, adds the location to `sys.path` and imports the required
458+
module into the global namespace before as part of class setup.
459+
460+
During teardown, those changes are reverted.
457461
"""
462+
458463
up = os.path.dirname
464+
global_validate_one = "validate_one"
459465
file_dir = up(os.path.abspath(__file__))
460-
script_dir = os.path.join(up(up(up(file_dir))), 'scripts')
466+
467+
script_dir = os.path.join(up(up(up(file_dir))), "scripts")
461468
sys.path.append(script_dir)
462-
from validate_docstrings import validate_one
463-
globals()['validate_one'] = validate_one
469+
470+
try:
471+
from validate_docstrings import validate_one
472+
globals()[global_validate_one] = validate_one
473+
except ImportError:
474+
# Import will fail if the pandas installation is not inplace.
475+
raise pytest.skip("pandas/scripts directory does not exist")
476+
464477
yield
478+
479+
# Teardown.
465480
sys.path.pop()
466-
del globals()['validate_one']
481+
del globals()[global_validate_one]
467482

468483
def _import_path(self, klass=None, func=None):
469484
"""

0 commit comments

Comments
 (0)