the wiki of cscosine
How to configure a project configured for a smooth VS Code experience with pytest-based testing and debugging.
VS Code will prompt you to install recommended extensions automatically.
They are defined in:
.vscode/extensions.json
extensions.json{
"recommendations": [
"ms-python.python",
"ms-python.debugpy"
]
}
Python extension Python extension for VS Code โ Provides:
debugpy debugpy โ Powers the debugging engine used by VS Code
All configuration lives in:
.vscode/
settings.json{
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
launch.json{
"version": "0.2.0",
"configurations": [
{
"name": "โถ Debug all tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["-s", "--run-all"],
"justMyCode": false
}
]
}
tasks.json{
"version": "2.0.0",
"tasks": [
{
"label": "Create venv",
"type": "shell",
"command": "python -m venv .venv",
"problemMatcher": []
},
{
"label": "Install deps",
"type": "shell",
"command": "${command:python.interpreterPath} -m pip install -e .[dev]",
"problemMatcher": []
},
{
"label": "Pre-commit install",
"type": "shell",
"command": "pre-commit install",
"problemMatcher": []
},
{
"label": "Pre-commit run (all files)",
"type": "shell",
"command": "pre-commit run --all-files",
"problemMatcher": []
},
{
"label": "Setup Project",
"dependsOn": [
"Create venv",
"Install deps",
"Pre-commit install",
"Pre-commit run (all files)"
],
"dependsOrder": "sequence",
"problemMatcher": []
}
]
}
Recommended workflow:
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -e .[dev]
code .
Select:
โถ Debug all tests
Click:
pytest tests/test_file.py::test_name