Skip to content

BLD: Install scripts tests only during inplace #22413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this causes an issue but from what I've tested locally if using the imperative skip validate_docstrings stays in globals as does the modification to system path. Perhaps we should ensure that code gets executed in the except block here?

Copy link
Member Author

@gfyoung gfyoung Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fair point regarding system path modification.
  • Not sure how validate_docstrings stays in globals if the import fails in the first place...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd : Addressed the change in follow-up (#22456)


yield

# Teardown.
sys.path.pop()
del globals()['validate_one']
del globals()[global_validate_one]

def _import_path(self, klass=None, func=None):
"""
Expand Down