This is not particularly well verified; it's just a gross idea.
(defun py-do-it () (interactive) (if (string-match (rx bos "test_") (file-name-nondirectory (buffer-file-name))) (compile "py.test") (py-execute-buffer))) (add-hook 'python-mode-hook (lambda () (local-set-key (kbd "F5") ;or whatever 'py-do-it)))
offby1
source share