Skip to content

Use directory for current buffer if pytest-project-root-files are not found #26

@sr105

Description

@sr105

I don't know elisp well enough to know if there's a better way to do this (hence an issue and not a pull request). This code returns the directory of the current buffer if there isn't a project root. That way, I can write tests in a single file where I'm just testing out some code.

Untouched; only changed the name.

(defun pytest-find-project-root-recursive (&optional dirname)
  (let ((dn
         (if dirname
             dirname
           (file-name-directory buffer-file-name))))
    (cond ((funcall pytest-project-root-test dn) (expand-file-name dn))
          ((equal (expand-file-name dn) "/") nil)
        (t (pytest-find-project-root-recursive
             (file-name-directory (directory-file-name dn)))))))

Try to find a project root and fall back to the current directory.

(defun pytest-find-project-root (&optional dirname)
  (or (pytest-find-project-root-recursive dirname)
      (file-name-directory buffer-file-name)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions