asdf
asdf copied to clipboard
asdf.open leaves behind an open file if it can't sort out how to open it
The following test illustrates:
# test_open_fail.py
from pathlib import Path
import asdf
import pytest
def test_asdf(tmp_path):
path = tmp_path / "empty.asdf"
Path(path).touch()
with asdf.open(path) as af:
pass
When run with pytest test_open_fail.py --open-files, the test fails as expected with
E ValueError: Input object does not appear to be an ASDF file or a FITS with ASDF extension
But also produces a teardown error, since it leaves the file open:
E AssertionError: File(s) not closed:
E /private/var/folders/jg/by5st33j7ps356dgb4kn8w900001n5/T/pytest-of-jdavies/pytest-157/test_asdf0/empty.asdf