- OS: XXX (Windows, macOS, latest Ubuntu LTS)
- Shell: XXX (Command Prompt, PowerShell, bash, fish)
- Python
- Distribution: XXX (CPython, miniconda)
- Version: XXX (2.7, latest 3.x)
- VS Code: XXX (Insiders)
ALWAYS:
- Check the
Outputwindow underPythonfor logged errors - Have
Developer Toolsopen to detect any errors - Consider running the tests in a multi-folder workspace
- Focus on in-development features (i.e. experimental debugger and language server)
Scenarios
- Interpreter is shown in the status bar
- An interpreter can be manually specified using the
Select Interpretercommand - Detected system-installed interpreters
- Detected an Anaconda installation
- (Linux/macOS) Detected all interpreters installed w/ pyenv detected
-
"python.pythonPath"triggers an update in the status bar -
Run Python File in Terminal -
Run Selection/Line in Python Terminal- Right-click
- Command
-
Shift+Enter
Sample file:
import requests
request = requests.get("https://drive.google.com/uc?export=download&id=1_9On2-nsBQIw3JiY43sWbrF8EjrqrR4U")
with open("survey2017.zip", "wb") as file:
file.write(request.content)
import zipfile
with zipfile.ZipFile('survey2017.zip') as zip:
zip.extractall('survey2017')
import shutil, os
shutil.move('survey2017/survey_results_public.csv','survey2017.csv')
shutil.rmtree('survey2017')
os.remove('survey2017.zip')- Shift+Enter to send selected code in sample file to terminal works
ALWAYS:
-
Use the latest version of Anaconda
-
Realize that
condais slow -
Create an environment with a space in their path somewhere as well as upper and lowercase characters
-
Make sure that you do not have
python.pythonPathspecified in yoursettings.jsonwhen testing automatic detection -
Do note that the
Select Interpreterdrop-down window scrolls -
Detected a single virtual environment at the top-level of the workspace folder on Mac when when
pythoncommand points to default Mac Python installation orpythoncommand fails in the terminal.- Appropriate suffix label specified in status bar (e.g.
(venv))
- Appropriate suffix label specified in status bar (e.g.
-
Detected a single virtual environment at the top-level of the workspace folder on Windows when
pythonfails in the terminal.- Appropriate suffix label specified in status bar (e.g.
(venv))
- Appropriate suffix label specified in status bar (e.g.
-
Detected a single virtual environment at the top-level of the workspace folder
- Appropriate suffix label specified in status bar (e.g.
(venv)) -
Create Terminalworks- Steals focus
-
"python.terminal.activateEnvironment": falsedeactivates automatically running the activation script in the terminal
- After the language server downloads it is able to complete its analysis of the environment w/o requiring a restart
- Appropriate suffix label specified in status bar (e.g.
-
Detect multiple virtual environments contained in the directory specified in
"python.venvPath" -
Detected all conda environments created with an interpreter
- Appropriate suffix label specified in status bar (e.g.
(condaenv)) - Prompted to install Pylint
- Asked whether to install using conda or pip
- Installs into environment
-
Create Terminalworks-
"python.terminal.activateEnvironment": falsedeactivates automatically running the activation script in the terminal
-
- After the language server downloads it is able to complete its analysis of the environment w/o requiring a restart
- Appropriate suffix label specified in status bar (e.g.
-
(Linux/macOS until
-mis supported) Detected the virtual environment created by pipenv- Appropriate suffix label specified in status bar (e.g.
(pipenv)) - Prompt to install Pylint uses
pipenv install --dev -
Create Terminalworks-
"python.terminal.activateEnvironment": falsedeactivates automatically running the activation script in the terminal
-
- After the language server downloads it is able to complete its analysis of the environment w/o requiring a restart
- Appropriate suffix label specified in status bar (e.g.
-
(Linux/macOS) Virtual environments created under
{workspaceFolder}/.direnv/python-{python_version}are detected (for direnv and itslayout python3support)- Appropriate suffix label specified in status bar (e.g.
(venv))
- Appropriate suffix label specified in status bar (e.g.
Sample files:
# example.py
import os
print('Hello,', os.environ.get('WHO'), '!')# .env
WHO=world
PYTHONPATH=some/path/somewhere
SPAM='hello ${WHO}'
ALWAYS:
-
Make sure to use
Reload Windowbetween tests to reset your environment -
Note that environment files only apply under the debugger
-
Environment variables in a
.envfile are exposed when running under the debugger -
"python.envFile"allows for specifying an environment file manually -
envFilein alaunch.jsonconfiguration works -
simple variable substitution works
-
pythonPathsetting in yourlaunch.jsonoverrides yourpython.pythonPathdefault setting
ALWAYS:
- Check under the
Problemstab to see e.g. if a linter is raising errors
- LS is downloaded using HTTP (no SSL) when the "http.proxyStrictSSL" setting is false
- An item with a cloud icon appears in the status bar indicating progress while downloading the language server
- Installing
requestsin virtual environment is detected- Import of
requestswithout package installed is flagged as unresolved - Create a virtual environment
- Install
requestsinto the virtual environment
- Import of
[Prompting to install Pylint is covered under Environments above]
For testing the disablement of the default linting rules for Pylint:
# pylintrc
[MESSAGES CONTROL]
enable=bad-names# example.py
foo = 42 # Marked as a disallowed name.- Installation via the prompt installs Pylint as appropriate
- Uses
--userfor system-install of Python - Installs into a virtual environment environment directly
- Uses
- Pylint works
- The existence of a
pylintrcfile turns off the default rules
Note:
-
You can use the
Run Lintingcommand to run a newly installed linter -
When the extension installs a new linter, it turns off all other linters
-
flake8 works
-
Select linterlists the linter and installs it if necessary
-
-
mypy works
-
Select linterlists the linter and installs it if necessary
-
-
pycodestyle works
-
Select linterlists the linter and installs it if necessary
-
-
prospector works
-
Select linterlists the linter and installs it if necessary
-
-
pydocstyle works
-
Select linterlists the linter and installs it if necessary
-
-
pylama works
-
Select linterlists the linter and installs it if necessary
-
-
3 or more linters work simultaneously (make sure you have turned on the linters in your
settings.json)-
Run Lintingruns all activated linters -
"python.linting.enabled": falsedisables all linters - The
Enable Lintingcommand changes"python.linting.enabled"
-
-
"python.linting.lintOnSaveworks
Please also test for general accuracy on the most "interesting" code you can find.
-
"python.autoComplete.extraPaths"works -
"python.autocomplete.addBrackets": truecauses auto-completion of functions to append() - Auto-completions works
Sample file:
# There should be _some_ change after running `Format Document`.
import os,sys;
def foo():pass- Prompted to install a formatter if none installed and
Format Documentis run- Installing
autopep8works - Installing
blackworks - Installing
yapfworks
- Installing
- Formatters work with default settings (i.e.
"python.formatting.provider"is specified but not matching*Pathor*Argssettings)- autopep8
- black
- yapf
- Formatters work when appropriate
*Pathand*Argssettings are specified (use absolute paths; use~if possible)- autopep8
- black
- yapf
-
"editor.formatOnType": trueworks and has expected results
-
Extract Variableworks- You are prompted to install
ropeif it is not already available
- You are prompted to install
-
Extract methodworks- You are prompted to install
ropeif it is not already available
- You are prompted to install
-
Sort Importsworks
- Configurations work (see
package.jsonand the"configurationSnippets"section for all of the possible configurations) - Running code from start to finish w/ no special debugging options (e.g. no breakpoints)
- Breakpoint-like things
- Breakpoint
- Set
- Hit
- Conditional breakpoint
- Expression
- Set
- Hit
- Hit count
- Set
- Hit
- Expression
- Logpoint
- Set
- Hit
- Breakpoint
- Stepping
- Over
- Into
- Out
- Can inspect variables
- Through hovering over variable in code
-
Variablessection of debugger sidebar
- Remote debugging works
- ... over SSH
- ... on other branches
- App Engine
import unittest
MODULE_SETUP = False
def setUpModule():
global MODULE_SETUP
MODULE_SETUP = True
class PassingSetupTests(unittest.TestCase):
CLASS_SETUP = False
METHOD_SETUP = False
@classmethod
def setUpClass(cls):
cls.CLASS_SETUP = True
def setUp(self):
self.METHOD_SETUP = True
def test_setup(self):
self.assertTrue(MODULE_SETUP)
self.assertTrue(self.CLASS_SETUP)
self.assertTrue(self.METHOD_SETUP)
class PassingTests(unittest.TestCase):
def test_passing(self):
self.assertEqual(42, 42)
def test_passing_still(self):
self.assertEqual("silly walk", "silly walk")
class FailingTests(unittest.TestCase):
def test_failure(self):
self.assertEqual(42, -13)
def test_failure_still(self):
self.assertEqual("I'm right!", "no, I am!")-
Run All Unit Teststriggers the prompt to configure the test runner - Tests are discovered (as shown by code lenses on each test)
- Code lens for a class runs all tests for that class
- Code lens for a method runs just that test
-
Run Testworks -
Debug Testworks - Module/suite setup methods are also run (run the
test_setupmethod to verify)
-
- while debugging tests, an uncaught exception in a test does not
cause
debugpyto raiseSystemExitexception.
def test_passing():
assert 42 == 42
def test_failure():
assert 42 == -13-
Run All Unit Teststriggers the prompt to configure the test runner-
pytestgets installed
-
- Tests are discovered (as shown by code lenses on each test)
-
Run Testworks -
Debug Testworks
-
- A
Diagnosticis shown in the problems pane for each failed/skipped test- The
Diagnostics are organized according to the file the test was executed from (not necessarily the file it was defined in) - The appropriate
DiagnosticRelatedInformationis shown for eachDiagnostic - The
DiagnosticRelatedInformationreflects the traceback for the test
- The
- Code lenses appears
-
Run Testlens works (and status bar updates as appropriate) -
Debug Testlens works - Appropriate ✔/❌ shown for each test
-
- Status bar is functioning
- Appropriate test results displayed
-
Run All Unit Testsworks -
Discover Unit Testsworks (resets tests result display in status bar) -
Run Unit Test Method ...works -
View Unit Test Outputworks - After having at least one failure,
Run Failed Testsworks
-
Configure Unit Testsworks- quick pick for framework (and its settings)
- selected framework enabled in workspace settings
- framework's config added (and old config removed)
- other frameworks disabled in workspace settings
-
Configure Unit Testsdoes not close if it loses focus - Cancelling configuration does not leave incomplete settings
- The first
"request": "test"entry in launch.json is used for running unit tests