@@ -448,22 +448,37 @@ class TestValidator(object):
448
448
@pytest .fixture (autouse = True , scope = "class" )
449
449
def import_scripts (self ):
450
450
"""
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.
457
461
"""
462
+
458
463
up = os .path .dirname
464
+ global_validate_one = "validate_one"
459
465
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" )
461
468
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
+
464
477
yield
478
+
479
+ # Teardown.
465
480
sys .path .pop ()
466
- del globals ()['validate_one' ]
481
+ del globals ()[global_validate_one ]
467
482
468
483
def _import_path (self , klass = None , func = None ):
469
484
"""
0 commit comments