从emacs运行py.test

时间:2010-04-14 07:14:55

标签: python emacs pytest

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

1 个答案:

答案 0 :(得分: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)))