ionrock / pytest-el

Run py.test on testing functions, classes, modules and entire suites in Emacs.
55 stars 26 forks source link

Wrong type argument: stringp, nil #38

Open twmr opened 1 year ago

twmr commented 1 year ago

When pytest-run is run while the current buffer is e.g. a magit buffer, the following error is output

Wrong type argument: stringp, nil

This is because pytest-find-test-runner-names runs (file-name-directory buffer-file-name), which raises the above error when run inside a buffer that doesn't have a buffer-file-name.

twmr commented 1 year ago

A possible fix is to check the value of buffer-file-name in pytest-find-test-runner.

 ;;; Utility functions
 (defun pytest-find-test-runner ()
-  (let ((result
-     (cl-reduce '(lambda (x y) (or x y))
-         (mapcar 'pytest-find-test-runner-names pytest-project-names))))
-    (if result
-    result
-      pytest-global-name)))
+  (if buffer-file-name
+      (if-let ((result
+                (cl-reduce '(lambda (x y) (or x y))
+                           (mapcar 'pytest-find-test-runner-names pytest-project-names))))
+          result
+        pytest-global-name)
+    pytest-global-name))

but probably the check could also be added to pytest-find-test-runner-names