'Regression test for https://github.com/astropy/astropy/issues/6168
The ResourceWarning shows up when (in python 3+) you try to
open a non-FITS file when using a filename.'

@pytest.mark.skipif(six.PY2, reason='ResourceWarning    is    not    created    in    Python    2')
def test_no_resource_warning_raised_on_non_fits_file(self):

    filename = self.temp('not-fits.fits')
    with open(filename, mode='w') as f:
        f.write('#    header    line\n')
        f.write('0.1    0.2\n')
    with catch_warnings(ResourceWarning) as ws:
        with open(filename, mode='rb') as f:
            with pytest.raises(OSError):
                fits.open(f, ignore_missing_end=False)
            assert (not f.closed)
        with open(filename, mode='rb') as f:
            with pytest.raises(OSError):
                fits.open(f, ignore_missing_end=True)
            assert (not f.closed)
        with pytest.raises(OSError):
            fits.open(filename, ignore_missing_end=False)
        with pytest.raises(OSError):
            fits.open(filename, ignore_missing_end=True)
    assert (len(ws) == 0)
