[emacs] Fix django test run to output test path

This commit is contained in:
2026-01-14 17:34:14 -05:00
parent 941c727d38
commit 27dd61084d

View File

@ -43,14 +43,46 @@
(cls cls) (cls cls)
(t nil)))) (t nil))))
(defun django--ensure-env (root)
(let ((default-directory root))
(when (fboundp 'envrc-reload)
(envrc-reload))))
(defface django-test-command-face
'((t :weight bold :foreground "orange" :height 1.15))
"Face used for Django test commands.")
(defun django--insert-command-header (buf root command)
"Insert a loud command header at the top of BUF."
(with-current-buffer (get-buffer-create buf)
(let ((inhibit-read-only t))
(save-excursion
(goto-char (point-min))
(insert (propertize (make-string 72 ?═) 'face 'shadow) "\n")
(insert (propertize
(format "$ (cd %s && %s)\n" root command)
'face 'django-test-command-face))
(insert (propertize (make-string 72 ?═) 'face 'shadow) "\n\n")))))
(defun django-run-tests (&optional module selector) (defun django-run-tests (&optional module selector)
(interactive) (interactive)
(let* ((module-part (or module "")) (let* ((root (django--project-root))
(module-part (or module ""))
(selector-part (if selector (concat "." selector) "")) (selector-part (if selector (concat "." selector) ""))
(param (string-trim (concat module-part selector-part))) (param (string-trim (concat module-part selector-part)))
(command (format "python manage.py test --keepdb %s" param))) (command (format "python manage.py test --keepdb %s" param))
(message "Running command: %s" command) (buf "*Django tests*"))
(projectile-run-async-shell-command-in-root command "*Django tests*"))) ;; Ensure envrc/direnv is current
(let ((default-directory root))
(when (fboundp 'envrc-reload) (envrc-reload)))
;; Start the process (this may clear/initialize the buffer)
(projectile-run-async-shell-command-in-root command buf)
;; Now insert header at top (won't get wiped)
(django--insert-command-header buf root command)
(pop-to-buffer buf)))
(defun django-run-test-at-point () (defun django-run-test-at-point ()
(interactive) (interactive)