Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running py.test from emacs

What I would like is for C-c C-c 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. How would I do this? I am using emacs 23.1.1 with python-mode and can access py.test from the command line.

like image 762
Nikwin Avatar asked Apr 14 '10 07:04

Nikwin


People also ask

How do I run Python code in Emacs?

Once you open your python file in Emacs, you will need to start the python process with: M-x run-python or C-c C-p , which creates an inferior python shell buffer. This buffer will be created by a horizontal split, and the active buffer will be the one containing the python file.


1 Answers

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)))
like image 90
offby1 Avatar answered Oct 18 '22 03:10

offby1