Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ __ https://melpa.org/
__ https://stable.melpa.org/


3.0.0 (not yet released)
------------------------

* add a ``python-pytest-directories`` command with interactive
multi-directory selection
(`#21 <https://github.com/wbolster/emacs-python-pytest/issues/21>`_)
(`#31 <https://github.com/wbolster/emacs-python-pytest/pull/31>`_)

2.0.0 (2020-08-04)
------------------

Expand All @@ -376,9 +384,10 @@ __ https://stable.melpa.org/
(`#18 <https://github.com/wbolster/emacs-python-pytest/issues/18>`_)
(`#26 <https://github.com/wbolster/emacs-python-pytest/pull/26>`_)

* add python-pytest-files command with interactive multi-file selection
* add ``python-pytest-files`` command with interactive multi-file
selection

* improve python-pytest-file-dwim heuristic for nested functions/classes
* improve ``python-pytest-file-dwim`` heuristic for nested functions/classes

* make ``next-error`` and related-commands work

Expand Down
56 changes: 40 additions & 16 deletions python-pytest.el
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ When non-nil only ‘test_foo()’ will match, and nothing else."
["Run tests for specific files"
("f" "Test file (dwim)" python-pytest-file-dwim)
("F" "Test this file" python-pytest-file)
("m" "Test multiple files" python-pytest-files)]
("m" "Test multiple files" python-pytest-files)
("m" "Test multiple directories" python-pytest-directories)]
["Run tests for current function/class"
("d" "Test def/class (dwim)" python-pytest-function-dwim)
("D" "Test this def/class" python-pytest-function)]])
Expand Down Expand Up @@ -201,13 +202,30 @@ Additional ARGS are passed along to pytest.
With a prefix argument, allow editing."
(interactive
(list
(python-pytest--select-test-files)
(python-pytest--select-test-files :type 'file)
(python-pytest-arguments)))
(setq args (-concat args (-map 'python-pytest--shell-quote files)))
(python-pytest--run
:args args
:edit current-prefix-arg))

;;;###autoload
(defun python-pytest-directories (directories &optional args)
"Run pytest on DIRECTORIES, using ARGS.

When run interactively, this allows for interactive directory selection.

Additional ARGS are passed along to pytest.
With a prefix argument, allow editing."
(interactive
(list
(python-pytest--select-test-files :type 'directory)
(python-pytest-arguments)))
(setq args (-concat args (-map 'python-pytest--shell-quote directories)))
(python-pytest--run
:args args
:edit current-prefix-arg))

;;;###autoload
(defun python-pytest-function (file func args)
"Run pytest on FILE with FUNC (or class).
Expand Down Expand Up @@ -516,30 +534,36 @@ Example: ‘MyABCThingy.__repr__’ becomes ‘test_my_abc_thingy_repr’."
(python-pytest--relative-file-name file)
(python-pytest--find-test-file file)))

(cl-defun python-pytest--select-test-files ()
(cl-defun python-pytest--select-test-files (&key type)
"Interactively choose test files."
(cl-block nil
(let ((test-files
(->> (projectile-project-files (python-pytest--project-root))
(-sort 'string<)
(projectile-sort-by-recentf-first)
(projectile-test-files)))
(done-message (propertize "[finish test file selection]" 'face 'success))
(choices)
(choice)
(selection-active t))
(unless test-files
(let* ((test-files
(->> (projectile-project-files (python-pytest--project-root))
(-sort 'string<)
(projectile-sort-by-recentf-first)
(projectile-test-files)))
(test-directories
(->> test-files
(-map 'file-name-directory)
(-uniq)
(-sort 'string<)))
(candidates (if (eq type 'file) test-files test-directories))
(done-message (propertize "[finish test file selection]" 'face 'success))
(choices)
(choice)
(selection-active t))
(unless candidates
(user-error "No test files found"))
(while (and selection-active test-files)
(while (and selection-active candidates)
(setq choice (completing-read
"Choose test files: "
(if choices (cons done-message test-files) test-files)
(if choices (cons done-message candidates) candidates)
nil t))
(if (s-equals-p choice done-message)
(setq selection-active nil)
(setq
choices (cons choice choices)
test-files (-remove-item choice test-files))))
candidates (-remove-item choice candidates))))
(cl-return (reverse choices)))))

(defun python-pytest--maybe-save-buffers ()
Expand Down