Skip to content

Instantly share code, notes, and snippets.

@abingham
Last active April 28, 2017 17:25
Show Gist options
  • Save abingham/8377114eec25d8578cf0 to your computer and use it in GitHub Desktop.
Save abingham/8377114eec25d8578cf0 to your computer and use it in GitHub Desktop.
Emacs routine for running python tests and displaying the results in a buffer.
(defun run-python-tests (root-dir test-subdir buffer-name)
(interactive)
(let ((default-directory root-dir)
(buff (get-buffer-create buffer-name)))
(display-buffer buff)
(shell-command (concat "python -m unittest discover " test-subdir) buff)
(with-current-buffer buff
(compilation-mode))))
; This hook runs the tests after each save, a TDD-esque workflow.
(add-hook 'after-save-hook
(lambda () (run-python-tests "~/projects/project_name/"
"project_name/test"
"*python-tests*")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment