Ⅰ. 插件描述
Plugin for running python unit tests in vimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'ameade/qtpy-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'ameade/qtpy-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'ameade/qtpy-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/ameade/qtpy-vim
Ⅳ. 文档说明
qtpy.vim
A simple way of running python unit tests from within VIM based on the cursor
location.
Useful for receiving immediate feedback as you write tests, despite what test
runner or framework your project uses to run its tests.
http://www.vim.org/scripts/script.php?script_id=3888
Usage
To use this plugin, make sure ftplugins are enabled, via "filetype on" in your
.vimrc.
Whenever a command is triggered a small message displays informing you that
the plugin is running a certain action. In the above call, you would see
something like this::
Running tests for class
When tests are successful a green bar appears. If you have any number of fails
you get a red bar with a line-by-line list of line numbers and errors.
Run all tests in current file::
:QTPY file
Run all tests in current class::
:QTPY class
Run current test at cursor location::
:QTPY method
If you would like to see the complete qtpy output you can add an optional verbose
flag to any of the commands for qtpy. For the previous command, it would
look like::
:QTPY class verbose
This would open a split scratch buffer that you can fully interact with. You
can close this buffer with ':wq' or you can hit 'q' at any moment in that buffer
to close it.
The previous test session display can be toggled with::
:QTPY session
If for some reason you need to reset and clear all global variables that affect
the plugin you can do so by running the following command::
:QTPY clear
Configuration
qtpy is configured to work with nosetests by default, however, using qtpy with
other unit tests runners is simple. Just set the necessary variables in your
For example, insert these lines into your .vimrc to use QTPY with Py.Test::
" for use with Py.Test
let g:qtpy_shell_command = "py.test --tb=short"
let g:qtpy_class_delimiter = "::"
let g:qtpy_method_delimiter = "::"
The delimiter variables are used with constructing the test path to pass into
the test runner. Such as "py.test /testfolder/testfile.py::TestClass::TestMethod"
for the example above where the first '::' is the class_delimiter and the second
is the method_delimiter
I recommend mapping keys to qtpy commands for easy running. To do so, insert
commands like this into your .vimrc::
" QTPY
au FileType python nnoremap <F8> :QTPY method verbose<CR>
au FileType python nnoremap <F9> :QTPY session<CR>
au FileType python nnoremap <silent><Leader>c <Esc>:QTPY class verbose<CR>
The 'au FileType python' ensures these mappings only occur in a python file.
Shell Support
This plugin provides a way to have a better shell experience when runningverbose flag by using the Conque.vim plugin. If you have this
most excellent piece of Vim plugin (see: http://www.vim.org/scripts/script.php?script_id=2771)
then qtpy.vim will use that instead of Vim's own dumb shell environment.
License
MIT
Copyright (c) 2011-2013 Alex Meade <mr.alex.meade [at] gmail [dot] com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Attribution
The core functionality of this plugin was brought over from pytest.vim. Which is
more focused on soley running py.test unit tests. That project can be found
here: https://github.com/alfredodeza/pytest.vim
Copyright (c) 2011 Alfredo Deza <alfredodeza [at] gmail [dot] com>