PyTest
pytest runner and view annotator for sublime text
Details
Installs
- Total 5K
- Win 3K
- Mac 1K
- Linux 1K
Dec 21 | Dec 20 | Dec 19 | Dec 18 | Dec 17 | Dec 16 | Dec 15 | Dec 14 | Dec 13 | Dec 12 | Dec 11 | Dec 10 | Dec 9 | Dec 8 | Dec 7 | Dec 6 | Dec 5 | Dec 4 | Dec 3 | Dec 2 | Dec 1 | Nov 30 | Nov 29 | Nov 28 | Nov 27 | Nov 26 | Nov 25 | Nov 24 | Nov 23 | Nov 22 | Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 2 |
Mac | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
py.test integration for Sublime Text
This plugin runs your tests and on failure annotates your files using the tracebacks.
Common Workflow
The defaults: it will run your tests on save; it will not show an output panel but annotate your views on failures instead. Like so:
Which test it will run depends on the red/green status of the previous run, and if you're currently editing a test file or an implementation file. It should work really okay. Set "mode": "manual"
and just use your own key bindings if you think that's stupid. See Default.sublime-commands
for some examples.
Config
At least look at the global settings. You usually have to edit the pytest
setting to point at your py.test from your current virtualenv (the default is to run your global py.test which is usually not what you want). E.g.
"pytest": "~/venvs/{project_base_name}/bin/py.test"
OR:
"pytest": ".env\\Scripts\\py.test"
OR even:
"pytest": ["venv/path/to/python", "-m", "pytest"]
The plugin will expand ${project_path}, ${project_base_name}, ${file}, etc. as usual. It will respect your project-settings
like:
{
"folders":
[
{
"path": "."
}
],
"settings": {
"PyTest": {
"mode": "auto",
"options": "--tb=short -l -ff",
},
}
}
You probably should add a keybinding to show/hide the output panel quickly. You could use TogglePanel as well, but this one also brings the keyboard focus to the panel.
{ "keys": ["ctrl+'"], "command": "pytest_toggle_panel" },
Maybe a keybinding to run only the test under the cursor(s) as well:
{ "keys": ["ctrl+shift+'"], "command": "pytest_run_test_under_cursor"},
But that command is also available via the context menu.
The third most useful keybinding could be
{ "keys": ["ctrl+alt+'"], "command": "pytest_toggle_phantoms"},
to quickly show/hide the annotations (in sublime parlance 'phantoms') b/c they can get quite annoying and in your way if you have a lot of failures or generally large tracebacks.
You can disable this plugin via a command (ctrl+shift+p
and start typing pytest deactivate
). This setting will then be persisted in your project settings (if any).
Install
End-users should just do the normal install using Package Control
searching for PyTest
.
Hackers can manually download/clone from github and put it in your Packages directory. You have to run Package Control: Satisfy Dependencies
after that to pull in lxml
.
You can go fancy of course, and add this repo to Package Control
.
- Open up the command palette (
ctrl+shift+p
), and findPackage Control: Add Repository
. Then enter the URL of this repo:https://github.com/kaste/PyTest
in the input field. - Open up the command palette again and find
Package Control: Install Package
, and just search forPyTest
. (just a normal install)
Manual Theme Tweaking
The plugin tries to tweak your theme so that you get a green/red notification after each test run. (You can disable this via the settings.) If this doesn't work out, consider a manual tweak: you really should add
{
"class": "status_bar",
"settings": ["pytest_is_red"],
"layer0.tint": [155, 7, 8], // -RED
},
to your .sublime-theme
to flash the status bar early if there are failures.
Likewise, add
{
"class": "status_bar",
"settings": ["pytest_is_green"],
"layer0.tint": [8, 131, 8], // -GREEN
},
{
"class": "label_control",
"settings": ["pytest_is_green"],
"parents": [{"class": "status_bar"}],
"color": [19, 21, 32],
},
to get a status bar notification if we're green. Add these styles at the end of your theme file, at least they must come after the default status_bar
styles because these styles are generally applied top-down. Read more about how to customize a theme here.