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

Use context managers in tests to avoid pytest.PytestUnraisableExceptionWarning:Exception ignored in: <_io.FileIO [closed]> #1776

Open
matthewfeickert opened this issue Feb 15, 2022 · 0 comments · May be fixed by #1784
Assignees
Labels
chore Other changes that don't modify src or test files help wanted Extra attention is needed / contributions welcome tests pytest

Comments

@matthewfeickert
Copy link
Member

In PR #1773 it was noticed that resulted in pytest.PytestUnraisableExceptionWarning:Exception ignored in: <_io.FileIO [closed]> warnings from opening files like

spec = json.load(open(datadir.join("workspace_integer_data.json")))

which can be avoid by using a context manager to properly close the file like

pyhf/tests/test_export.py

Lines 424 to 425 in c2c2891

with open(datadir.join("workspace_integer_data.json")) as spec_file:
spec = json.load(spec_file)

If this is implemented everywhere in the tests, then the warning ignore of

'ignore: Exception ignored in:pytest.PytestUnraisableExceptionWarning', #FIXME: Exception ignored in: <_io.FileIO [closed]>

can be removed.

@matthewfeickert matthewfeickert added tests pytest chore Other changes that don't modify src or test files help wanted Extra attention is needed / contributions welcome labels Feb 15, 2022
@matthewfeickert matthewfeickert self-assigned this Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Other changes that don't modify src or test files help wanted Extra attention is needed / contributions welcome tests pytest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant