Nikwin
Nikwin

Reputation: 6756

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.

Upvotes: 9

Views: 1459

Answers (1)

offby1
offby1

Reputation: 6983

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)))

Upvotes: 8

Related Questions