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

JP-3552: use tmp_path instead of tmpdir, enable no:legacypath as a tox factor #8327

Merged
merged 16 commits into from
Mar 15, 2024

Conversation

emolter
Copy link
Collaborator

@emolter emolter commented Mar 1, 2024

Resolves JP-3552

Closes #8311

This PR replaces all instances tmpdir and tmpdir_factory pytest fixtures with tmp_path and tmp_path_factory fixtures, as recommended by pytest (see here), so that these are returning standard pathlib.Path instances instead of legacy py.path.local instances.

Jenkins run here

Checklist for maintainers

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • Make sure the JIRA ticket is resolved properly

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 53.21%. Comparing base (4cc0ac1) to head (06b0731).
Report is 27 commits behind head on master.

Files Patch % Lines
jwst/scripts/okify_regtests.py 0.00% 3 Missing ⚠️
jwst/regtest/conftest.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #8327       +/-   ##
===========================================
- Coverage   75.15%   53.21%   -21.95%     
===========================================
  Files         470      389       -81     
  Lines       38604    38463      -141     
===========================================
- Hits        29014    20468     -8546     
- Misses       9590    17995     +8405     
Flag Coverage Δ
nightly ?

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emolter emolter changed the title JP-3552: updated pytest to use tmp_path instead of tmpdir JP-3552: use tmp_path instead of tmpdir, enable no:legacypath as a tox factor Mar 7, 2024
@emolter emolter marked this pull request as ready for review March 7, 2024 14:58
@emolter emolter requested a review from a team as a code owner March 7, 2024 14:58
Copy link
Collaborator

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

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

Looks great! 👏

Just some minor comments (and confusion) below.

return os.path.join(data_path, filename)
@pytest.fixture(scope="module")
def data_path():
return pathlib.Path(__file__).parents[0] / "data"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Path().parents[0] is the equivalent to Path().parent?

@@ -35,7 +35,7 @@


@pytest.fixture(scope="module", params=file_roots) # ids=ids)
def run_pipeline(jail, rtdata_module, request):
def run_pipeline(tmp_cwd_module, rtdata_module, request):
Copy link
Collaborator

Choose a reason for hiding this comment

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

For all these cases where the rtdata_module fixture is used, tmp_cwd_module is not needed, as its already included within rtdata_module. Not a bug, but not necessary.

Same with tests that use the rtdata fixture - no need to use tmp_cwd, as it's already loaded as a fixture when rtdata gets loaded. It's fine to use if you need its return value, but otherwise, it's redundant.

This is not a problem introduced by this PR, as it seems there were already a bunch of tests that used _jail, rtdata and jail, rtdata_module together already.

But it might be best to remove this pattern so that it is not copied further. =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, yes, there are a lot of these instances. Hopefully I'll get all of them

@@ -50,7 +50,7 @@ def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix):


@pytest.fixture()
def run_photom(jail, rtdata):
def run_photom(tmp_cwd_module, rtdata):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what is going on here. one module-scoped fixture (tmp_cwd_module) and one function-scoped fixture ('rtdata') are being used simultaneously. Would be good to sort out what is going on. I can't run regtests over here. ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

looks to me like both the run_photom and run_extract1d fixtures should be module-scoped to permit multiple tests of their output without rerunning. I passed just rtdata_module into these and all the tests in the file pass locally.

@@ -76,7 +76,7 @@ def test_photom(run_photom, fitsdiff_default_kwargs):


@pytest.fixture()
def run_extract1d(jail, rtdata):
def run_extract1d(tmp_cwd_module, rtdata):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see comment above

@emolter
Copy link
Collaborator Author

emolter commented Mar 13, 2024

New regtest run started here.

edit: Regression tests are failing for the two test_nirspec_ifu_spec2 tests where there seemed to be an implicit scope mismatch before. Of course it Works On My MachineTM so I started this run that only runs tests in that file.

@emolter
Copy link
Collaborator Author

emolter commented Mar 14, 2024

Finally, regression tests for just nirspec_ifu_spec2 passed here. Between this and the previous regtest run, hopefully everything is working now, but I started this new full run just in case.

Copy link
Collaborator

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

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

Looks great! Very nice cleanup.

And now you really know how all this regtest infrastructure works. Congrats! 😅

I wouldn't worry about the coverage check. It was jus reporting coverage on the unit tests plus one regtest, so incomplete.

@hbushouse
Copy link
Collaborator

Latest full regtest run has failures that are all unrelated to this PR (they're due to a separate update to datamodels). So this looks good. I'm approving and merging. Nice work everyone - that's a wrap.

@hbushouse hbushouse merged commit d787bea into spacetelescope:master Mar 15, 2024
27 of 29 checks passed
@emolter emolter deleted the JP-3552 branch March 15, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment