Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortcut to run current Python unit test in VSCode

Tags:

The question is regarding Visual Studio Code (VSCode from here) and python VSCode extension that finds and runs py.test tests.

Is it possible to assign some shortcut to run current (under cursor) test method and/or test class?

I really like the ability to run single test straight from VSCode, but my workflow is not optimal since it is necessary to click it and just use some shortcut.

clickable run test

This image shows the buttons that appear when tests are found and can be run. I would like to know if it is possible to just use some custom shortcut instead of clicking this buttons.

like image 311
mislavcimpersak Avatar asked Apr 11 '17 10:04

mislavcimpersak


People also ask

How do I run a unit test in Visual Studio python?

Open a Python project. Once the project is loaded in Visual Studio, right-click your project in Solution Explorer and select the unittest or pytest framework from the Properties Test tab. If you use the pytest framework, you can specify test location and filename patterns using the standard pytest .

How do I run a test case in VS Code Python?

Once you have the Python extension installed and a Python file open within the editor, a test beaker icon will be displayed on the VS Code Activity bar. The beaker icon is for the Test Explorer view. When opening the Test Explorer, you will see a Configure Tests button if you don't have a test framework enabled.


1 Answers

Try Test Explorer UI and Python Test Explorer for Visual Studio Code.

The command list: enter image description here

However, run-test-at-cursor doesn't work for me. I use run-file. Moreover, maybe you should join workbench.action.files.save, test-explorer.reload, and test-explorer.run-test-at-cursor with a macro extension.

like image 106
Mystic Lin Avatar answered Sep 24 '22 10:09

Mystic Lin