Does anyone know how to run only one python test with Test Explorer in Visual Studio Code?
I have installed https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter.
I am using pytest.
In the picture below:
If I press "Run Test" then only one test runs, but I do not see any log / output.
To see the output I have to press "Run", but this runs all my tests. This is incredibly frustrating.
I would like to be able to run only the one test with the Visual Studio Code interface and see the log for this run.
I did not find one elegant way to just run one test and then see the correct sampled/collected output from that test, but I found a way to run only the test I was working on by tagging it with:
@pytest.mark.run_this_test
and hit F5 anywhere in VSCode to just run this test over and over again. The PyTest debug config looks like this:
{
"name": "PyTest",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"module": "pytest",
"args": [
"-s", "-m run_this_test"
],
"justMyCode": false,
"pythonPath": "${config:python.pythonPath}",
"env": {
"PYTHONPATH": "${workspaceRoot}"
}
This 'tagging' does not scale in a team obviously, but it works for me alone.
I created a repo containing my solution: https://bitbucket.org/geircode/vscode-testsetup-python
To test it:
From VS Code test explorer it's possible. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With