Skip to content

Remove use of pytest-openfiles#14041

Merged
pllim merged 4 commits intoastropy:mainfrom
Cadair:remove-use-of-openfiles
Jan 25, 2023
Merged

Remove use of pytest-openfiles#14041
pllim merged 4 commits intoastropy:mainfrom
Cadair:remove-use-of-openfiles

Conversation

@Cadair
Copy link
Member

@Cadair Cadair commented Nov 24, 2022

As demonstrated in #14040 we no longer need to use pytest-openfiles to fail the test build if files are left open. This PR purges any mention of it from basically everywhere. I split the test runner changes into a different commit because we might not want to break that if it's still in use downstream somewhere?

Close #14040

@astrofrog
Copy link
Member

Does this mean we could basically stop maintaining pytest-openfiles? (after advertising on astropy-dev that it is no longer needed)

@Cadair
Copy link
Member Author

Cadair commented Nov 24, 2022

I think so.

@WilliamJamieson
Copy link
Contributor

I worry that removing pytest-openfiles might cause us to miss some errors like the one that we discovered in the asdf 2.14.0 release, which was fixed by asdf-format/asdf#1241 (and released in asdf 2.14.1).

@Cadair will removing pytest-openfiles catch bugs like this?

@pllim
Copy link
Member

pllim commented Nov 29, 2022

We should test that hypothesis. We can take this PR and reintroduce the handler leak that it is supposed to catch.

@Cadair
Copy link
Member Author

Cadair commented Nov 30, 2022

I would expect that to lead to a resource warning, but pushes to my test PR to check are welcome!

@jdavies-st
Copy link
Contributor

Note the caveats on filtering ResourceWarning alone:

pytest-dev/pytest#9825

It seems that filtering for ResourceWarning allows more latitude in constructing pytest fixtures that don't close files until teardown, but also it seems that it doesn't enforce doing so, or catch instances when they are not closed.

Agree it would be nice to test famous open files cases we have in this repo and see if ResourceWarning filter would catch it.

@Cadair
Copy link
Member Author

Cadair commented Nov 30, 2022

I am not that bothered about when in the pytest cycle they get raised, to me having them be thrown late makes sense because you don't know if something else (i.e. fixture teardown) is going to shut them. Having it fail a specific test is less of a concern to me as having the build fail.

@pllim pllim added this to the v5.3 milestone Dec 9, 2022
@pllim
Copy link
Member

pllim commented Dec 9, 2022

@WilliamJamieson and @jdavies-st , did @Cadair sufficiently address your concerns or is some follow-up required? Thanks!

@WilliamJamieson
Copy link
Contributor

@WilliamJamieson and @jdavies-st , did @Cadair sufficiently address your concerns or is some follow-up required? Thanks!

I moved/duplicated the test that astropy flagged into ASDF awhile ago. I am fine with this change.

@nstarman nstarman requested a review from jdavies-st January 17, 2023 17:22
Copy link
Contributor

@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.

This looks good to me. It seems that converting ResourceWarning to an error will catch runtime cases, and that this will give more flexibility in building pytest fixtures that provide already open files.

It does allow one to be sloppy with the fixtures and not close them, but it seems that pytest itself must do proper teardown of the fixtures before the python session is ended, or else they would show up as ResourceWarnings, but they do not.

So I'm fine with this.

@pllim pllim force-pushed the remove-use-of-openfiles branch from df9564b to d083b17 Compare January 25, 2023 22:17
Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

I added back a section about testing for open files but mention the new way it is done. LGTM as long as CI passes. Thanks!

pllim added a commit to pllim/pytest-openfiles that referenced this pull request Jan 25, 2023
@pllim
Copy link
Member

pllim commented Jan 25, 2023

devdeps failure is not related. Thanks, all!

@pllim pllim merged commit eaddc17 into astropy:main Jan 25, 2023
@pllim
Copy link
Member

pllim commented Jan 25, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants