简体   繁体   English

从emacs运行py.test

[英]Running py.test from emacs

What I would like is for Cc Cc to run py.test and display the output in the other buffer if the name of the file being edited begins with test_, and to normally run py-execute-buffer otherwise. 我想要的是Cc Cc运行py.test并在另一个缓冲区中显示输出,如果正在编辑的文件的名称以test_开头,否则通常运行py-execute-buffer。 How would I do this? 我该怎么做? I am using emacs 23.1.1 with python-mode and can access py.test from the command line. 我正在使用带有python-mode的emacs 23.1.1,并且可以从命令行访问py.test。

This isn't particularly well-tested; 这不是特别好的测试; it's just a rough 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)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM