Skip to content

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

Open
@matthewfeickert

Description

@matthewfeickert

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.

Metadata

Metadata

Labels

choreOther changes that don't modify src or test fileshelp wantedExtra attention is needed / contributions welcometestspytest

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions