Skip to content
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

Update tmpdir usage to tmp_path and enable no:legacypath #64

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions ci_watson/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def pytest_runtest_setup(item):


@pytest.fixture(scope='function')
def _jail(tmpdir):
def _jail(tmp_path):
"""Perform test in a pristine temporary working directory."""
old_dir = os.getcwd()
os.chdir(tmpdir.strpath)
os.chdir(tmp_path)
try:
yield tmpdir.strpath
yield str(tmp_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to just yield the tmp_path instead of its string form?

That is what is done here

https://github.com/astropy/astroquery/blob/4d2311745752ffc0133e439053dd4046e4a8294b/astroquery/conftest.py#L70-L78

in a similar fixture I wrote based on _jail.

This would allow one to be sure one is pathlib compatible, though it might break a few things downstream. Though perhaps the breaking is good?

Or one could leave this fixture unchanged and make a properly-named fixtured called tmp_cwd that can be used that yields a pathlib.Path object, and can be transitioned to at anytime by any package that uses ci-watson.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the question and comments.

I added the str to keep this consistent for the downstream (as you mentioned changing it to a Path might break things).

Given the naming (_jail) I would have assumed this was not intended for "public" use. So replacing it with a public fixture (or having the downstream libraries implement their own for their needs) seems reasonable.

To use -p no:legacyapth here (to keep this test suite updated) _jail would need to be updated (as is done in this PR).

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this package, this fixture is also used for HSTCAL. So unless you feel like patching up hstcal and acstools test suite, backward compatibility is a must.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely not! Let's keep backwards compatibility. 😅

finally:
os.chdir(old_dir)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ junit_family = xunit2
filterwarnings =
error
ignore:numpy.ndarray size changed:RuntimeWarning
addopts = "-p no:legacypth"
pllim marked this conversation as resolved.
Show resolved Hide resolved
Loading