Skip to content

Correctly handle -m and -k flags #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
Merged
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
31 changes: 26 additions & 5 deletions python-pytest.el
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ When non-nil only ‘test_foo()’ will match, and nothing else."
("-s" "no output capture" "--capture=no")
(python-pytest:-v)]]
["Selection, filtering, ordering"
[("-k" "only names matching expression" "-k=")
("-m" "only marks matching expression" "-m=")
[(python-pytest:-k)
(python-pytest:-m)
" "] ;; visual alignment
[("--dm" "run doctests" "--doctest-modules")
("--nf" "new first" "--new-first")
Expand Down Expand Up @@ -417,9 +417,7 @@ With a prefix ARG, allow editing."
"Transform ARGS so that pytest understands them."
(-->
args
(python-pytest--switch-to-option it "--color" "--color=yes" "--color=no")
(python-pytest--quote-string-option it "-k")
(python-pytest--quote-string-option it "-m")))
(python-pytest--switch-to-option it "--color" "--color=yes" "--color=no")))

(defun python-pytest--switch-to-option (args name on-replacement off-replacement)
"Look in ARGS for switch NAME and turn it into option with a value.
Expand All @@ -441,6 +439,29 @@ When present ON-REPLACEMENT is substituted, else OFF-REPLACEMENT is appended."
(format "%s %s" option it)))
args))

(defun python-pytest--read-quoted-argument-for-short-flag (prompt initial-input history)
"Read a quoted string for use as a argument after a short-form command line flag."
(let* ((input (read-from-minibuffer prompt initial-input nil nil history))
(quoted-input (python-pytest--shell-quote input))
(formatted-input (format " %s" quoted-input)))
formatted-input))

(transient-define-argument python-pytest:-k ()
:description "only names matching expression"
:class 'transient-option
:argument "-k"
:allow-empty nil
:key "-k"
:reader 'python-pytest--read-quoted-argument-for-short-flag)

(transient-define-argument python-pytest:-m ()
:description "only marks matching expression"
:class 'transient-option
:argument "-m"
:allow-empty nil
:key "-m"
:reader 'python-pytest--read-quoted-argument-for-short-flag)

(transient-define-argument python-pytest:-v ()
:description "verbosity"
:class 'transient-switches
Expand Down