astropy / astropy

Astronomy and astrophysics core library
https://www.astropy.org
BSD 3-Clause "New" or "Revised" License
4.45k stars 1.78k forks source link

"OSError: [WinError 6] The handle is invalid" on Windows for some votable validation tests #14791

Open pllim opened 1 year ago

pllim commented 1 year ago

astropy v5.3rc1

_____________________________________________ test_validate_output_invalid _____________________________________________

    def test_validate_output_invalid():
...
        # When output is not set, check that validate returns a bool
>       validate_out = validate(invalid_votable_filepath)

C:\...\astropy\io\votable\tests\table_test.py:368:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

source = 'C:\\...\\astropy\\io\\votable\\tests\\data\\regression.xml'
output = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, xmllint = False
filename = 'C:\\...\\astropy\\io\\votable\\tests\\data\\regression.xml'

    def validate(source, output=sys.stdout, xmllint=False, filename=None):
...
        content_buffer.seek(0)
>       output.write(f"Validation report for {filename}\n\n")
E       OSError: [WinError 6] The handle is invalid

C:\...\astropy\io\votable\table.py:309: OSError
______________________________________________ test_validate_output_valid ______________________________________________

    def test_validate_output_valid():
...
        # When output is not set, check that validate returns a bool
>       validate_out = validate(valid_votable_filepath)

C:\...\astropy\io\votable\tests\table_test.py:390:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

source = 'C:\\...\\astropy\\io\\votable\\tests\\data\\valid_votable.xml'
output = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, xmllint = False
filename = 'C:\\...\\astropy\\io\\votable\\tests\\data\\valid_votable.xml'

    def validate(source, output=sys.stdout, xmllint=False, filename=None):
...
>       output.write(f"Validation report for {filename}\n\n")
E       OSError: [WinError 6] The handle is invalid

C:\...\astropy\io\votable\table.py:309: OSError
_______________________________________________ test_validate_tilde_path _______________________________________________

home_is_data = None

    def test_validate_tilde_path(home_is_data):
>       validate(os.path.join("~", "valid_votable.xml"))

C:\...\astropy\io\votable\tests\table_test.py:397:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

source = 'C:\\...\\astropy\\io\\votable\\tests\\data\\valid_votable.xml'
output = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, xmllint = False
filename = 'C:\\...\\astropy\\io\\votable\\tests\\data\\valid_votable.xml'

    def validate(source, output=sys.stdout, xmllint=False, filename=None):
...
        content_buffer.seek(0)
>       output.write(f"Validation report for {filename}\n\n")
E       OSError: [WinError 6] The handle is invalid

C:\...\astropy\io\votable\table.py:309: OSError
______________________________________________ test_validate_xmllint_true ______________________________________________

mock_subproc_popen = <MagicMock name='Popen' id='...'>

    @mock.patch("subprocess.Popen")
    def test_validate_xmllint_true(mock_subproc_popen):
...
>       assert validate(get_pkg_data_filename("data/empty_table.xml"), xmllint=True)

C:\...\astropy\io\votable\tests\vo_test.py:836:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

source = 'C:\\...\\astropy\\io\\votable\\tests\\data\\empty_table.xml'
output = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, xmllint = True
filename = 'C:\\...\\astropy\\io\\votable\\tests\\data\\empty_table.xml'

    def validate(source, output=sys.stdout, xmllint=False, filename=None):
...
        content_buffer.seek(0)
>       output.write(f"Validation report for {filename}\n\n")
E       OSError: [WinError 6] The handle is invalid

C:\...\astropy\io\votable\table.py:309: OSError

Note to self: Had the hardest building astropy from source on Windows to debug this. Future self, please see https://github.com/pypa/setuptools/issues/2028#issuecomment-1540141355 and then if astropy.__version__ not found, delete the extra astropy folder in site-packages. pytest from CLI complains about too many conftest.py but calling astropy.test(...) works.

pllim commented 1 year ago

I am asking also over at https://github.com/pytest-dev/pytest/discussions/10976 .

All I can figure out is that they choke when validate() does not take any output override, so it defaults to output=sys.stdout and then errors out on sys.stdout.write(some_string).

pllim commented 1 year ago

Still seeing this in testing v6.0rc1 locally. 🤷

FAILED io/votable/tests/test_table.py::test_validate_output_invalid - OSError: [WinError 6] The handle is invalid
FAILED o/votable/tests/test_table.py::test_validate_output_valid - OSError: [WinError 6] The handle is invalid
FAILED io/votable/tests/test_table.py::test_validate_tilde_path - OSError: [WinError 6] The handle is invalid
FAILED io/votable/tests/test_vo.py::test_validate_xmllint_true - OSError: [WinError 6] The handle is invalid
pllim commented 7 months ago

And still the same problem in v6.1rc1 locally.

pllim commented 5 days ago

And v7.0.0rc1