TESTER PRODUCTIVITY

Turning a VS Code Task Into a One-Click Test Runner (and Agents)

Every time I switch to a terminal, type out a pytest command with three flags and wait for it, I've broken my focus. It's a small thing, but small things add up. VS Code tasks remove that interruption: they wire a shell command into the editor, so a test run is a shortcut or a Command Palette entry away. Because the configuration lives in .vscode/tasks.json and is committed with the repo, everyone who clones the project gets the same runners on day one.

That shared definition matters more once coding agents are working in the same repo. When Copilot's agent mode or another agent runs your tests, it builds its own command unless you tell it what to use, and the version it builds may differ from the one your team uses. The simplest fix is to make tasks thin wrappers around one script that the agent is told to use too. Then a click and an agent's run do exactly the same thing.

Below is a practical tasks.json for a Python API suite, a few corrections to advice that's commonly repeated, and a couple of tasks built for reviewing agent work.

Build an API Automation Framework With Node.js

Learn Node.js, Cucumber, GitHub Copilot, APIs, CI/CD, and modern automation by building a complete framework.

Learn more

A first tasks.json for pytest or Behave

Create .vscode/tasks.json in the project root:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Tests: Smoke",
      "type": "shell",
      "command": "${workspaceFolder}/scripts/test.sh",
      "args": ["-m", "smoke"],
      "group": { "kind": "test", "isDefault": true },
      "presentation": { "reveal": "always", "panel": "shared", "clear": true },
      "problemMatcher": []
    }
  ]
}

Here's what each part does:

  • group with isDefault makes this the default test task, so Tasks: Run Test Task in the Command Palette runs it without showing a picker.
  • "panel": "shared" with "clear": true reuses one terminal panel and clears it, so you always see only the latest run.
  • "problemMatcher": [] tells VS Code not to scan the output for problems and stops it asking you to choose a matcher. A real matcher comes later.
  • args as a separate array avoids most quoting problems with marker expressions.

The command calls a repository script rather than pytest directly. The script handles the virtual environment, loads the right .env file and defaults to the safe subset of tests. I describe building it in turning a Bash alias into a one-command test runner. For Behave, the script (or a second one) runs behave instead, and the task looks the same.

Don't rely on the editor's interpreter setting

A common tip is to set python.defaultInterpreterPath in .vscode/settings.json and expect tasks to use that environment. That setting is for the Python extension. A shell task runs in a terminal process, and whether your virtual environment is active there depends on terminal activation, which isn't something I'd rely on. The predictable options are to call the interpreter explicitly (.venv/bin/python -m pytest) or call a script that does. If teammates use Windows, give the task a "windows" block with its own command, because a Bash script and .venv/bin paths won't work there as written.

A small task menu

One task is useful. Three to five well-named ones cover most of a day. Prefix every label with Tests: so they group together in Tasks: Run Task:

{
  "label": "Tests: Full Regression",
  "type": "shell",
  "command": "${workspaceFolder}/scripts/test.sh",
  "args": ["-m", "not live_api", "--tb=long"],
  "group": "test",
  "presentation": { "reveal": "always", "panel": "shared", "clear": true },
  "problemMatcher": []
},
{
  "label": "Tests: Smoke on Staging",
  "type": "shell",
  "command": "${workspaceFolder}/scripts/test.sh",
  "args": ["-m", "smoke"],
  "options": { "env": { "TARGET": "staging" } },
  "group": "test",
  "presentation": { "reveal": "always", "panel": "shared", "clear": true },
  "problemMatcher": []
}

Use options.env to set the environment rather than writing BASE_URL=... pytest into the command string. Inline variable assignment is shell syntax that PowerShell doesn't support, while options.env works with any shell. The script picks the environment file from TARGET, so the test code itself stays environment-agnostic, as I describe in when one API test suite covers multiple environments.

Clickable failures with a custom problem matcher

To make failures show up in the Problems panel with a link to the line, you need a problem matcher. I'm not aware of one for pytest built into VS Code, so define your own. Pytest's --tb=line option prints one line per failure in file:line: message form, which is easy to match:

{
  "label": "Tests: Failures to Problems",
  "type": "shell",
  "command": "${workspaceFolder}/scripts/test.sh",
  "args": ["--tb=line", "-m", "not live_api"],
  "group": "test",
  "problemMatcher": {
    "owner": "pytest",
    "fileLocation": ["autoDetect", "${workspaceFolder}"],
    "severity": "error",
    "pattern": {
      "regexp": "^(.+\\.py):(\\d+): (.+)$",
      "file": 1,
      "line": 2,
      "message": 3
    }
  }
}

The Testing view from the Python extension is another way to get clickable failures. I keep both: the Testing view for single tests while I'm writing, and tasks for the named runs I use every day. More editor tooling for API work is in VS Code extensions that speed up API testing.

Tasks for reviewing agent work

When an agent has been working on a branch, my review starts with two questions: did it change any assertions, and do the tests it touched still pass? Two tasks answer those in one click each:

{
  "label": "Review: Assertion Changes vs main",
  "type": "shell",
  "command": "git diff main...HEAD -- tests/ | grep -E '^[-+][^-+].*assert' || echo 'No assertion changes'",
  "presentation": { "reveal": "always", "panel": "shared", "clear": true },
  "problemMatcher": []
},
{
  "label": "Review: Evals (opt-in)",
  "type": "shell",
  "command": "${workspaceFolder}/scripts/test.sh",
  "args": ["-m", "llm"],
  "presentation": { "reveal": "always", "panel": "dedicated" },
  "problemMatcher": []
}

The first prints every added or removed assertion line in the test folder. A removed assertion or a loosened expected value is the change I most want to see before merging, because it's how a real regression gets passed off as an intentional update. The second runs model-dependent tests that cost money and time, which is why it's a deliberate click and never part of the default run.

Then point the agent at the same entry point. In .github/copilot-instructions.md, or whatever instruction file your agent reads, add something like "Run tests with scripts/test.sh. Do not run -m live_api or -m llm unless asked." Now there's one definition of how tests run, and both the task menu and the agent use it.

Keybindings and team adoption

Key preferences are personal, so they belong in each person's keybindings.json, not in the repo. Binding a specific task is one entry:

{
  "key": "ctrl+alt+s",
  "command": "workbench.action.tasks.runTask",
  "args": "Tests: Smoke"
}

Check that your chosen chord isn't already taken in the Keyboard Shortcuts editor first. For the team, commit tasks.json and add two lines to the README saying the runners exist. That does more for onboarding than a long page of instructions. There's more on building a smooth editor-to-GitHub workflow in developer workflows for testers.

A good task setup is boring in the best way: one click, the same command every time, for you, your teammates and your agents. If you want to set up a full API test project in VS Code with GitHub Copilot from scratch, my API testing courses walk through it.