run a collection of 1000 unit tests at once by clicking in the "Testing" view of the Activity Bar
you should see this error.
Traceback (most recent call last):
File "/home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/vscode_pytest/run_pytest_script.py", line 39, in <module>
data = sock.read(3000)
File "/home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/testing_tools/socket_manager.py", line 75, in read
data = part.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 2999: unexpected end of data
Finished running tests!
I believe the underlying issue is unicode characters in test function names, i.e. the circles in:
def test_ᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤᐤ952():
When running a large set of unit tests each test name is provided to the pytest invocation on the client
machine as command line args. If there are enough tests to cross a 1024 byte boundary (or maybe its 3000),
then there is a chance that PipeManager in socket_manager.py will do a read that does not terminate on a unicode code point boundary.
For example, say the character ᐤ is encoded as two bytes, A and B, then it's possible by reading 1024 bytes that
the final character of the bunch is only A, and that B will be available in a subsequent read. Decoding a string
under this condition will result in the above error:
I was able to confirm the above theory by patching by socket_manager as follows:
diff --git a/python_files/testing_tools/socket_manager.py b/python_files/testing_tools/socket_manager.py
index 31b78b254..b497c8c61 100644
--- a/python_files/testing_tools/socket_manager.py
+++ b/python_files/testing_tools/socket_manager.py
@@ -69,10 +69,14 @@ class PipeManager:
return self._reader.read(bufsize)
else:
# receive bytes and convert to string
+ part: bytes = self._socket.recv(bufsize)
while True:
- part: bytes = self._socket.recv(bufsize)
- data: str = part.decode("utf-8")
- return data
+ try:
+ data = part.decode("utf-8")
+ return data
+ except UnicodeDecodeError:
+ # try reading one more byte
+ part += self._socket.recv(1)
class SocketManager(object):
If I were to PR this I would like some feedback on this approach. It does rely on exception handling which isn't ideal. And reading one byte at a time seems inefficient. And could a genuine utf encoding error put this into an infinite loop? Are any of those issues severe enough to warrant improvements? (I think the last one is for sure.)
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
```
2024-05-22 14:55:26.221 [info] Experiment 'pythonaa' is active
2024-05-22 14:55:26.221 [info] Experiment 'pythonCreateEnvOnPipInstallcf' is active
2024-05-22 14:55:26.221 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-05-22 14:55:26.221 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-05-22 14:55:26.221 [info] Experiment 'pythonTestAdapter' is active
2024-05-22 14:55:26.221 [info] Default formatter is set to null for workspace /home/ubuntu/massive-tests
2024-05-22 14:55:26.221 [info] Python interpreter path: ./venv/bin/python
2024-05-22 14:55:26.256 [info] > pyenv which python
2024-05-22 14:55:26.256 [info] cwd: .
2024-05-22 14:55:26.311 [info] > . ./venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py
2024-05-22 14:55:26.311 [info] shell: bash
2024-05-22 14:55:26.333 [info] > /bin/python3 ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py
2024-05-22 14:55:26.333 [info] shell: bash
2024-05-22 14:55:26.350 [info] Setting environment variable VIRTUAL_ENV in collection to /home/ubuntu/massive-tests/venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-22 14:55:26.350 [info] Prepending environment variable PS1 in collection with (venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-05-22 14:55:26.350 [info] Prepending environment variable PATH in collection with /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash:/home/ubuntu/massive-tests/venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-22 14:55:26.351 [info] Send text to terminal: /bin/python3 /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariablesToFile.py /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash/envVars.txt
2024-05-22 14:55:27.098 [info] Starting Pylance language server.
2024-05-22 14:56:09.497 [info] Discover tests for workspace name: massive-tests - uri: /home/ubuntu/massive-tests
2024-05-22 14:56:09.497 [info] Running discovery for pytest using the new test adapter.
2024-05-22 14:56:09.498 [info] All environment variables set for pytest discovery: {"USER":"ubuntu","SSH_CLIENT":"172.19.160.1 54807 22","XDG_SESSION_TYPE":"tty","SHLVL":"0","MOTD_SHOWN":"pam","HOME":"/home/ubuntu","SSL_CERT_FILE":"/usr/lib/ssl/certs/ca-certificates.crt","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1001/bus","LOGNAME":"ubuntu","_":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/node","XDG_SESSION_CLASS":"user","VSCODE_CLI_REQUIRE_TOKEN":"30c43a77-5a4a-4596-a1c8-427121d317a3","XDG_SESSION_ID":"3","VSCODE_AGENT_FOLDER":"/home/ubuntu/.vscode-server","XDG_RUNTIME_DIR":"/run/user/1001","SSL_CERT_DIR":"/usr/lib/ssl/certs","LANG":"C.UTF-8","SHELL":"/bin/bash","PWD":"/home/ubuntu","SSH_CONNECTION":"172.19.160.1 54807 172.19.164.74 22","VSCODE_HANDLES_SIGPIPE":"true","LS_COLORS":"","RALLY_URL":"https://staging.sdvi.com","LESSCLOSE":"/usr/bin/lesspipe %s %s","LESSOPEN":"| /usr/bin/lesspipe %s","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","STAMP_PERSISTENCE_LOCATION":"/home/ubuntu/.config/sdvi-kick","RALLY_API_TOKEN":"HfzuhYgi6mhcVt+uZE1NovstPolsUt7JuskyvIHDPSYTKCXEghlo2q4m4SwIauu+","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","BROWSER":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/helpers/browser.sh","VSCODE_CWD":"/home/ubuntu","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/run/user/1001/vscode-ipc-ec5a8dcc-a31b-43f0-b262-73a2769eef2b.sock","PATH":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli:/home/ubuntu/.local/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin","PYTHONPATH":"/home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files","TEST_RUN_PIPE":"/run/user/1001/python-test-discovery-f24fcc81ccfdc66f0d0e.sock"}
2024-05-22 14:56:09.511 [info] > . ./venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py
2024-05-22 14:56:09.511 [info] shell: bash
2024-05-22 14:56:09.529 [info] > ./venv/bin/python -m pytest -p vscode_pytest --collect-only .
2024-05-22 14:56:09.529 [info] cwd: .
2024-05-22 14:56:09.646 [info] ============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-8.2.1, pluggy-1.5.0
2024-05-22 14:56:09.646 [info] rootdir: /home/ubuntu/massive-tests
configfile: pytest.ini
2024-05-22 14:56:09.806 [info] collected 1000 items
2024-05-22 14:56:09.806 [info]
MASSIVE SNIP of similar lines to reduce character count
2024-05-22 14:56:09.807 [info]
MASSIVE SNIP of similar lines to reduce character count
2024-05-22 14:56:09.807 [info]
MASSIVE SNIP of similar lines to reduce character count
2024-05-22 14:56:09.807 [info]
MASSIVE SNIP of similar lines to reduce character count
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.807 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
2024-05-22 14:56:09.808 [info]
Type: Bug
Behaviour
Steps to reproduce:
you should see this error.
I believe the underlying issue is unicode characters in test function names, i.e. the circles in:
When running a large set of unit tests each test name is provided to the pytest invocation on the client machine as command line args. If there are enough tests to cross a 1024 byte boundary (or maybe its 3000), then there is a chance that PipeManager in socket_manager.py will do a read that does not terminate on a unicode code point boundary.
For example, say the character ᐤ is encoded as two bytes, A and B, then it's possible by reading 1024 bytes that the final character of the bunch is only A, and that B will be available in a subsequent read. Decoding a string under this condition will result in the above error:
I was able to confirm the above theory by patching by socket_manager as follows:
If I were to PR this I would like some feedback on this approach. It does rely on exception handling which isn't ideal. And reading one byte at a time seems inefficient. And could a genuine utf encoding error put this into an infinite loop? Are any of those issues severe enough to warrant improvements? (I think the last one is for sure.)
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)``` 2024-05-22 14:55:26.221 [info] Experiment 'pythonaa' is active 2024-05-22 14:55:26.221 [info] Experiment 'pythonCreateEnvOnPipInstallcf' is active 2024-05-22 14:55:26.221 [info] Experiment 'pythonRecommendTensorboardExt' is active 2024-05-22 14:55:26.221 [info] Experiment 'pythonTerminalEnvVarActivation' is active 2024-05-22 14:55:26.221 [info] Experiment 'pythonTestAdapter' is active 2024-05-22 14:55:26.221 [info] Default formatter is set to null for workspace /home/ubuntu/massive-tests 2024-05-22 14:55:26.221 [info] Python interpreter path: ./venv/bin/python 2024-05-22 14:55:26.256 [info] > pyenv which python 2024-05-22 14:55:26.256 [info] cwd: . 2024-05-22 14:55:26.311 [info] > . ./venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py 2024-05-22 14:55:26.311 [info] shell: bash 2024-05-22 14:55:26.333 [info] > /bin/python3 ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py 2024-05-22 14:55:26.333 [info] shell: bash 2024-05-22 14:55:26.350 [info] Setting environment variable VIRTUAL_ENV in collection to /home/ubuntu/massive-tests/venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-22 14:55:26.350 [info] Prepending environment variable PS1 in collection with (venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":false} 2024-05-22 14:55:26.350 [info] Prepending environment variable PATH in collection with /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash:/home/ubuntu/massive-tests/venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-22 14:55:26.351 [info] Send text to terminal: /bin/python3 /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariablesToFile.py /home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash/envVars.txt 2024-05-22 14:55:27.098 [info] Starting Pylance language server. 2024-05-22 14:56:09.497 [info] Discover tests for workspace name: massive-tests - uri: /home/ubuntu/massive-tests 2024-05-22 14:56:09.497 [info] Running discovery for pytest using the new test adapter. 2024-05-22 14:56:09.498 [info] All environment variables set for pytest discovery: {"USER":"ubuntu","SSH_CLIENT":"172.19.160.1 54807 22","XDG_SESSION_TYPE":"tty","SHLVL":"0","MOTD_SHOWN":"pam","HOME":"/home/ubuntu","SSL_CERT_FILE":"/usr/lib/ssl/certs/ca-certificates.crt","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1001/bus","LOGNAME":"ubuntu","_":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/node","XDG_SESSION_CLASS":"user","VSCODE_CLI_REQUIRE_TOKEN":"30c43a77-5a4a-4596-a1c8-427121d317a3","XDG_SESSION_ID":"3","VSCODE_AGENT_FOLDER":"/home/ubuntu/.vscode-server","XDG_RUNTIME_DIR":"/run/user/1001","SSL_CERT_DIR":"/usr/lib/ssl/certs","LANG":"C.UTF-8","SHELL":"/bin/bash","PWD":"/home/ubuntu","SSH_CONNECTION":"172.19.160.1 54807 172.19.164.74 22","VSCODE_HANDLES_SIGPIPE":"true","LS_COLORS":"","RALLY_URL":"https://staging.sdvi.com","LESSCLOSE":"/usr/bin/lesspipe %s %s","LESSOPEN":"| /usr/bin/lesspipe %s","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","STAMP_PERSISTENCE_LOCATION":"/home/ubuntu/.config/sdvi-kick","RALLY_API_TOKEN":"HfzuhYgi6mhcVt+uZE1NovstPolsUt7JuskyvIHDPSYTKCXEghlo2q4m4SwIauu+","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","BROWSER":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/helpers/browser.sh","VSCODE_CWD":"/home/ubuntu","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/run/user/1001/vscode-ipc-ec5a8dcc-a31b-43f0-b262-73a2769eef2b.sock","PATH":"/home/ubuntu/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli:/home/ubuntu/.local/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin","PYTHONPATH":"/home/ubuntu/.vscode-server/extensions/ms-python.python-2024.6.0/python_files","TEST_RUN_PIPE":"/run/user/1001/python-test-discovery-f24fcc81ccfdc66f0d0e.sock"} 2024-05-22 14:56:09.511 [info] > . ./venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py 2024-05-22 14:56:09.511 [info] shell: bash 2024-05-22 14:56:09.529 [info] > ./venv/bin/python -m pytest -p vscode_pytest --collect-only . 2024-05-22 14:56:09.529 [info] cwd: . 2024-05-22 14:56:09.646 [info] ============================= test session starts ============================== platform linux -- Python 3.8.10, pytest-8.2.1, pluggy-1.5.0 2024-05-22 14:56:09.646 [info] rootdir: /home/ubuntu/massive-tests configfile: pytest.ini 2024-05-22 14:56:09.806 [info] collected 1000 items