[qutebrowser] Useful vim function for testing
Ryan Roden-Corrent
ryan at rcorre.net
Wed Jun 22 04:52:23 CEST 2016
I've been working with the tests a lot and thought I would share this vim
function in case anyone else finds it useful:
---
function! RunTest()
if (expand('%:e') == 'feature')
" this is a .feature file, run the corresponding .py test
let l:fname = expand('%:h') . '/test_' . expand('%:t:r') . '_bdd.py'
execute '!tox -e py35 -- ' . l:fname
let s:last_run = l:fname
elseif (expand('%:t') =~ 'test_.*\.py$')
" if this is a test_*.py file, run it directly
execute '!tox -e py35 -- ' . expand('%')
let s:last_run = expand('%')
elseif (exists('s:last_run'))
" we are not on a test file, so run the test we ran last time
execute '!tox -e py35 -- ' . s:last_run
endif
endfunction
nnoremap <F3> :call RunTest()<cr>
---
If the current buffer is 'test_foo.py', it runs that test. If it is
'foo.feature', it runs the corresponding feature test ('test_foo_bdd.py').
Otherwise, it runs whatever test you last ran.
I'm no vimscript wizard so there may very well be some mistakes in there, but it
works for me.
-Ryan
More information about the qutebrowser
mailing list