Here's how to make emacs run the current test method [*] (where your cursor is) when you press a key:
(setq imenu-auto-rescan t) ; ensure function names auto-refresh
(setq imenu-max-item-length 200) ; ensure function names are not truncated
(require 'which-func)
(defun which-py-function ()
(let* ((funname (which-function))
(fn (and (string-match "def \\([^(]+\\)" funname)
(match-string 1 funname))))
fn))
(defun run-current-zope-test () (interactive)
(compile (concat "/zope1/bin/zopectl test --tests-pattern='_tests$' --test-file-pattern='_tests$' -t " (which-py-function)) t))
(add-hook 'python-mode-hook (lambda () (local-set-key "\C-c\C-c" 'run-current-zope-test)))
Change the zopectl path to suit your system. The test will run in a compilation buffer, where you can click on any errors to jump to source.
| [*] | Actually it runs all methods whose name contains the name of the one you're in - how to make it more precise ? |