Add pytest run-command recipe
This commit is contained in:
parent
8ba027565b
commit
baf34a00e9
@ -6657,6 +6657,29 @@ current buffer:
|
||||
(list :command-name "edit"
|
||||
:command-line (format "sops %s" (buffer-file-name))))))
|
||||
|
||||
(defun run-command-recipe-pytest ()
|
||||
(when (and (derived-mode-p 'python-mode)
|
||||
(= 0 (call-process "python" nil nil nil "-c" "import pytest")))
|
||||
(let ((test-file-p (string-match-p "test" (or (buffer-file-name) ""))))
|
||||
(list
|
||||
(when (and (projectile-project-root)
|
||||
(file-exists-p (concat (file-name-as-directory (projectile-project-root))
|
||||
"tests")))
|
||||
(list :command-name "test all"
|
||||
:command-line "pytest tests"
|
||||
:working-dir (projectile-project-root)))
|
||||
(when test-file-p
|
||||
(list :command-name "test this file"
|
||||
:command-line (format "pytest %s" (buffer-file-name))))
|
||||
(when (and test-file-p (python-info-current-defun))
|
||||
(list :command-name "test this function"
|
||||
:command-line (format "pytest %s::%s"
|
||||
(buffer-file-name)
|
||||
(replace-regexp-in-string
|
||||
"\\."
|
||||
"::"
|
||||
(python-info-current-defun)))))))))
|
||||
|
||||
:general
|
||||
(leader-map "\"" #'run-command)
|
||||
(run-command-term-minor-mode-map [remap recompile] #'run-command-term-recompile)
|
||||
@ -6671,7 +6694,8 @@ current buffer:
|
||||
run-command-recipe-executables
|
||||
run-command-recipe-obelix
|
||||
run-command-recipe-kustomize
|
||||
run-command-recipe-sops)))
|
||||
run-command-recipe-sops
|
||||
run-command-recipe-pytest)))
|
||||
#+end_src
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user