making pytests run reliably in vscode and powershell script to spin off a test file quickly

1. requirements

  • there is 1 codeFile and 1 testFile
  • testFile is called *
  • test is called test_foo()
  • the only allowed separator on file (module) name is underscore _
  • no dots
  • no dashes
  • do not have code and tests in same file (I used to do that for katas, etc.)
  • you can use ptw for real-time testing there if needed

2. usage

  • have a custom keyboard shortcut for opening the test sidebar
  • CTRL + ALT + SHIFT + T
  • possibly also for running a particular test method / debug particular test method

3. creating code

  • lazy to keep creating an extra test file for each code file
  • now, I am ignoring the recommended folder structure at this moment
function create-pythonFiles($name) {
$codeFile = ("$name" -replace "\s", "_") -replace ".+", "$&.py"
$testFile = ("$name" -replace "\s", "_") -replace ".+", "$&"
New-Item $codeFile
New-Item $testFile
vsc .
Invoke-Item $codeFile
Invoke-Item $testFile
Set-Alias pyf create-pythonFiles
pyf SICP_01_01



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj


Infrastructure Support Engineer/Technical Writer ( with a passion for Python/writing documentation. More about me: