Install the following packages from PyPI:
- nose: the unit test runner;
- nose_machineout: The
machineoutplugin formats the
noseoutput so that Vim can parse it more easily;
- vim_bridge: This is required for the vim plugin scripts, to call directly into Python functions.
To run the unit tests for this project, you also need
- mock: Required to mock out the
vimobject in our test cases.
Clone the git repository:
git clone git://github.com/nvie/vim-pyunit.git cd vim-pyunit
Copy the file
- Open a Python file (or its corresponding unit test file named
It shows the errors inside a quickfix window, which will allow your to
quickly jump to the error locations by simply pressing
Source files vs. test files
vim-pyunit assumes that you have a single test file for each Python
source file. The settings
PyUnitTestsStructure determine how the plugin
finds which test files belong to which source files.
PyUnitTestsStructure setting is the most important one, because it
determines where the PyUnit plugin searches for source and test files.
There are three options:
- flat: Put all test files in a single test directory. File names are
composed by resembling the source's module structure, using underscores
as separators. For example, the test file for the source file
- side-by-side: Put all the test files in the same directory as the
source files. Test files are prefixed with
test_. For example, the test file for the source file
foo/test_bar.py. Use this setting when testing Django apps.
- follow-hierarchy: Put all the test files in a separate test
directory (specified by
PyUnitTestsRoot), but keep the same directory hierarchy as used in the source directory. For example, the test file for the source file
- nose: Put all the test files in a separate test
directory (specified by
PyUnitTestsRoot), but keep the same directory hierarchy as used in the source directory. As opposed to the
follow-hierarchylayout, the intermediate directories are not prefixed with
test_, only the last (file part) component is. For example, the test file for the source file
By default, the
vim-pyunit plugin defines the following keyboard
|F9||Switch between the source and the corresponding test file.
If the source or test file is not yet open, it is opened.
The plugin autodetects whether you have remapped the functions to custom
keyboard mappings. If so, if does not register the default mappings. So
to pick your own shortcut key mappings, simply add lines like this to your
noremap ,t :call PyUnitRunTests()<CR> noremap! ,t <Esc>:call PyUnitRunTests()<CR>
(Which would map the test runner to comma-T.
<F8> then remains what it
If you wish to disable any automatic keyboard mapping, simply set:
let no_pyunit_maps = 1
The plugin supports setting of the following variables:
||Shows the tests.||0 or 1||1|
||The command to run the unit test.||any string||"nosetests -q --with-machineout"|
||List of filenames indicating the project root.||list of file names||[".git", "setup.py", "setup.cfg"]|
||Stop the search for the project root at the user's home dir.||0 or 1||1|
||The filename prefix to use for test files.||any string||"test_"|
||Not implemented yet||0 or 1||n/a|
||The relative location where all source files live.||directory spec, or empty||""|
||The relative location where all tests live.||directory spec||"tests"|
||Specifies how you wish to organise your tests.||flat, follow-hierarchy, side-by-side||"follow-hierarchy"|
||Specifies where test files should be opened,
when oopened next to the source file. When set
||left, right, top, bottom, no||"right"|
||Ask to confirm creation of new test files.||0 or 1||1|
This plugin goes well together with the following plugin:
- flake8 (Python static syntax checker under