从emacs运行py.test

Nik*_*win 9 python emacs pytest

我想要的是Cc Cc运行py.test并在另一个缓冲区中显示输出,如果正在编辑的文件的名称以test_开头,否则通常运行py-execute-buffer.我该怎么做?我正在使用带有python-mode的emacs 23.1.1,并且可以从命令行访问py.test.

off*_*by1 8

这不是特别好的测试; 这只是一个粗略的想法.

(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)))
Run Code Online (Sandbox Code Playgroud)