Skip to content

Commit 92af1e9

Browse files
committed
Correctly handle -m and -k flags
Add a special reader helper to read shell arguments that should go after a short-form pytest flag. Fixes #36.
1 parent a2f88b1 commit 92af1e9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

python-pytest.el

+26-5
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ When non-nil only ‘test_foo()’ will match, and nothing else."
128128
("-s" "no output capture" "--capture=no")
129129
(python-pytest:-v)]]
130130
["Selection, filtering, ordering"
131-
[("-k" "only names matching expression" "-k=")
132-
("-m" "only marks matching expression" "-m=")
131+
[(python-pytest:-k)
132+
(python-pytest:-m)
133133
" "] ;; visual alignment
134134
[("--dm" "run doctests" "--doctest-modules")
135135
("--nf" "new first" "--new-first")
@@ -417,9 +417,7 @@ With a prefix ARG, allow editing."
417417
"Transform ARGS so that pytest understands them."
418418
(-->
419419
args
420-
(python-pytest--switch-to-option it "--color" "--color=yes" "--color=no")
421-
(python-pytest--quote-string-option it "-k")
422-
(python-pytest--quote-string-option it "-m")))
420+
(python-pytest--switch-to-option it "--color" "--color=yes" "--color=no")))
423421

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

442+
(defun python-pytest--read-quoted-argument-for-short-flag (prompt initial-input history)
443+
"Read a quoted string for use as a argument after a short-form command line flag."
444+
(let* ((input (read-from-minibuffer prompt initial-input nil nil history))
445+
(quoted-input (python-pytest--shell-quote input))
446+
(formatted-input (format " %s" quoted-input)))
447+
formatted-input))
448+
449+
(transient-define-argument python-pytest:-k ()
450+
:description "only names matching expression"
451+
:class 'transient-option
452+
:argument "-k"
453+
:allow-empty nil
454+
:key "-k"
455+
:reader 'python-pytest--read-quoted-argument-for-short-flag)
456+
457+
(transient-define-argument python-pytest:-m ()
458+
:description "only marks matching expression"
459+
:class 'transient-option
460+
:argument "-m"
461+
:allow-empty nil
462+
:key "-m"
463+
:reader 'python-pytest--read-quoted-argument-for-short-flag)
464+
444465
(transient-define-argument python-pytest:-v ()
445466
:description "verbosity"
446467
:class 'transient-switches

0 commit comments

Comments
 (0)