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.
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.
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)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With