Quickly execute Django tests.
This package provides a function to generate commands to run specific Django tests. Invoke the function anywhere on the python file, and you'll have a test command for that file. When the cursor is at the class or method name, it generates a specific command for it. You can see it in use here.
A quick feedback cycle is key for good and efficient development workflow. TDD helps with that, and this package aims to give you the necessary tooling when executing Django tests on Emacs.
This package is not on melpa yet. If you would like to install it in the meantime and you are using Emacs 29+ with built-in use-package and :vc support, you can:
(use-package django-test-runner
:ensure t
:vc (:url "https://github.com/bcfurtado/django-test-runner.el"
:rev :newest))
(use-package python
:after (django-test-runner)
:bind (:map python-mode-map
("<f10>" . django-test-runner)))Otherwise, save django-test-runner.el locally and install transient 0.3.0+ package. transient is available in melpa.
(load "~/.emacs.d/django-test-runner.el")
(require 'django-test-runner)
(define-key python-mode-map (kbd "<f10>") 'django-test-runner)- On a Django test case, go to a class or method that you want to execute the tests.
- Invoke
django-test-runnerfunction. - Choose the proper options on the pop-up. Press RET.
- Press RET again to accept
django-test-runner.elsuggestion.
- The compile command is always executed with the
comint-mode, unless--no-inputoption is selected. This behavior is required in casemanage.pytry to interact with you.commint-modeallows you to interact with the subprocess in case you need it. - For a better experience, keep the
--no-inputalways enabled and thecompilewill run withoutcomint-mode. Now you can usecompilation-modekeybind like g (recompile), M-g n (next-error) and M-g p (previous-error) on*compilation*buffer. - To save your command preferences, e.g. keep
--no-inputenabled by default, press C-x C-s(transient-save)while the pop-up is open.
- Compilation mode does not scroll down the buffer window as the output appears by default. If you want this behavior you should:
(setq compilation-scroll-output t)- It can be useful to automatically select
*compilation*buffer when the command is executed. You can achieve this behavior by advising thecompilecommand.
(defun follow-compilation (&rest args)
(when (get-buffer "*compilation*")
(switch-to-buffer-other-window "*compilation*")))
(advice-add 'compile :after follow-compilation)More information about the Django test options can be found on Django documentation.
Distributed under the GNU General Public License, version 3.
