Skip to content

Commit 68c2464

Browse files
committed
clean up python-pytest--current-defun helper
1 parent d970721 commit 68c2464

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

python-pytest.el

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,13 @@ When present ON-REPLACEMENT is substituted, else OFF-REPLACEMENT is appended."
436436

437437
(defun python-pytest--current-defun ()
438438
"Detect the current function/class (if any)."
439-
(save-excursion
440-
(let ((name (python-info-current-defun)))
441-
(unless name
442-
;; jumping seems to make it work on empty lines.
443-
;; todo: this could perhaps be improved.
439+
(or (python-info-current-defun)
440+
(save-excursion
441+
;; As a fallback, jumping seems to make it work on empty lines.
444442
(python-nav-beginning-of-defun)
445443
(python-nav-forward-statement)
446-
(setq name (python-info-current-defun)))
447-
(unless name
448-
(user-error "No class/function found"))
449-
name)))
444+
(python-info-current-defun))
445+
(user-error "No class/function found")))
450446

451447
(defun python-pytest--make-test-name (func)
452448
"Turn function name FUNC into a name (hopefully) matching its test name.

0 commit comments

Comments
 (0)