While moving the Python development environment to VSCode, I tried various things to run pytest in the VSCode environment, but for some reason the discovery failed and I got stuck for a while.
I am creating a new Python project in the VSCode environment connected by Remote Development.
I created the Python environment with poetry and introduced pytest for testing.
I confirmed from CUI that pytest can run poetry run pytest
without any problem, and when I tried to run the test from VSCode, the test discovery failed.
When doing test discovery with pytest from VSCode, for some reason it was treated as a failure if there was standard output. It has been pointed out from the following issues that it will fail if there is any standard output. https://github.com/microsoft/vscode-python/issues/6594 https://github.com/microsoft/vscode-python/issues/7574
If you are using TensorFlow, just doing ʻimport tensorflow as tf` will give you various warnings, which seems to be the cause.
It is as in the above issue. To control the output of TensorFlow, put a file like the following in your project with the name .env
.
.env
TF_CPP_MIN_LOG_LEVEL='2'
An environment variable for controlling the TF log output. By setting 2, WARNING will not appear. If you set it to 3, no error will occur.
If we can prevent other types of standard output in some way, we can take measures.
that's all. It took me some time to realize that the cause was standard output, so if it helps ...
Recommended Posts