csWiki

the wiki of cscosine


Project maintained by cscosine Hosted on GitHub Pages — Theme by mattgraham

Table Of Contents

Setup VS Code to Use Python Efficiently

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"
  ]
}

What these do:


โš™๏ธ Project Configuration

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": []
    }
  ]
}

๐Ÿ Environment Setup

Recommended workflow:

python -m venv .venv
source .venv/bin/activate   # Linux/macOS
.venv\Scripts\activate      # Windows

pip install -e .[dev]
code .

๐Ÿงช Running Tests

โ–ถ Run all tests (debug)


๐Ÿงช Run individual tests

Option 2 โ€” Terminal

pytest tests/test_file.py::test_name

๐Ÿ Summary