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

Test discovery fails with ValueError: I/O operation on closed file. #20826

Closed
fleimgruber opened this issue Mar 9, 2023 · 8 comments
Closed
Assignees
Labels
area-testing triage-needed Needs assignment to the proper sub-team

Comments

@fleimgruber
Copy link

fleimgruber commented Mar 9, 2023

OS: Windows
VS Code: 1.76.0
Python: venv created using Poetry and pyenv-win

Running the relevant test discovery command from CLI (PowerShell 7.2.1):

.\.venv\Scripts\python.exe C:\Users\LeimgruberF\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests

shows this error:

cwd: .
[ERROR 2023-2-9 17:9:52.58]: Error discovering pytest tests:
 [n [Error]: --- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 332, in _exit_function
    info('process shutting down')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 54, in info
    _logger.log(INFO, msg, *args)
Message: 'process shutting down'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 333, in _exit_function
    debug('running all "atexit" finalizers with priority >= 0')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 50, in debug
    _logger.log(DEBUG, msg, *args)
Message: 'running all "atexit" finalizers with priority >= 0'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 359, in _exit_function
    debug('running the remaining "atexit" finalizers')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 50, in debug
    _logger.log(DEBUG, msg, *args)
Message: 'running the remaining "atexit" finalizers'
Arguments: ()

	at ChildProcess.<anonymous> (c:\Users\LeimgruberF\.vscode\extensions\ms-python.python-2023.4.0\out\client\extension.js:2:244860)
	at Object.onceWrapper (node:events:646:26)
	at ChildProcess.emit (node:events:526:28)
	at maybeClose (node:internal/child_process:1092:16)
	at ChildProcess._handle.onexit (node:internal/child_process:302:5)]
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Mar 9, 2023
@eleanorjboyd
Copy link
Member

Hello! Could you try running pytest discovery in the terminal and see the result?

@fleimgruber
Copy link
Author

fleimgruber commented Mar 10, 2023

Hi @eleanorjboyd, thanks for the support.

Could you try running pytest discovery in the terminal and see the result?

I ran the command in the terminal (updated the description to be explicit I ran it in PowerShell), the output is reproducible and the same as above.

Edit: I did not look closely, now I see this output (I inserted the "... (more tests) ..." portion manually):

[{"rootid": ".", "root": "C:\\Users\\LeimgruberF\\dev\\the_project", "parents": [{"id": "./tests", "kind": "folder", "name": "tests", "parentid": ".", "relpath": ".\\tests"}, {"id": "./tests/test_device.py", "kind": "file", "name": "test_device.py", "parentid": "./tests", "relpath": ".\\tests\\test_device.py"}, {"id": "./tests/test_evaluate.py", "kind": "file", "name": "test_evaluate.py", "parentid": "./tests", "relpath": ".\\tests\\test_evaluate.py"}, ... (more tests) ... {"id": "./tests/test_storage_sqlite.py::test_sqlite_file_load", "name": "test_sqlite_file_load", "source": ".\\tests\\test_storage_sqlite.py:53", "markers": [], "parentid": "./tests/test_storage_sqlite.py"}]}]
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 332, in _exit_function
    info('process shutting down')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 54, in info
    _logger.log(INFO, msg, *args)
Message: 'process shutting down'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 333, in _exit_function
    debug('running all "atexit" finalizers with priority >= 0')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 50, in debug
    _logger.log(DEBUG, msg, *args)
Message: 'running all "atexit" finalizers with priority >= 0'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\logging\__init__.py", line 1086, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\tempfile.py", line 478, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
Call stack:
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 359, in _exit_function
    debug('running the remaining "atexit" finalizers')
  File "C:\Users\LeimgruberF\scoop\apps\pyenv\current\pyenv-win\versions\3.9.12\lib\multiprocessing\util.py", line 50, in debug
    _logger.log(DEBUG, msg, *args)
Message: 'running the remaining "atexit" finalizers'
Arguments: ()

@fleimgruber
Copy link
Author

@eleanorjboyd or did you mean to run it in the VS Code terminal? Happy to support in any other way.

@eleanorjboyd
Copy link
Member

yes- that would be great. Sorry for the delay!

@fleimgruber
Copy link
Author

Getting the same error as in #20826 (comment) from the VS Code terminal (which is a PowerShell).

@eleanorjboyd
Copy link
Member

Hi @fleimgruber, if pytest is unable to discover the tests correctly than we cannot parse that output and display it in our UI therefore you should look into getting the pytest error fixed and our discovery will be fix as well. Thanks!

@eleanorjboyd
Copy link
Member

closing as this is a pytest error not vscode- please reopen if you think that is not the case.

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@fleimgruber
Copy link
Author

fleimgruber commented Apr 11, 2023

For reference, this is the related upstream pytest issue: pytest-dev/pytest#5502.

What was causing the error for me was test code that imported from a module that imported a lot of dagster - which apparently does some offending (according to pytest authors) stdio handling at import time. I did not dig further into it, just removed the related tests.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants