2

I have a project all of whose packages, incl. nosetests itself, are installed in a virtualenv specific to that project, stored under ~/.virtualenvs. However, the M-x nosetests-one and M-x nosetests-all etc do not (obviously) even look into the virtualenv bin directory for commands, so these commands fail with an error message stating that the command nosetests could not be found; and even if that weren't the case, they'd be invoking the wrong nosetests binary because I need the tests to be invoked from within my virtualenv not the global environment.

I've tried several google searches to find a solution but I've not been able to find anything better than my existing hacky (but simple and reliable) approach of simply setting nose-global-name to a hardcoded value in the project's .dir-locals.el file:

((nil . ((nose-global-name . "~/.virtualenvs/myproject/bin/nosetests"))))

But, even though it's a viable solution, I'm hoping there's a more generic solution to this that doesn't require manual adjustment for every new project.

4

1 回答 1

2

看看这段代码。它将项目名称提取为(nose-find-project-root). 在你的情况下,它是myproject. 然后它nose-global-name暂时设置为您当前拥有的那个(因为当前项目名称是nosetests)。

(defun nosetests-all-virtualenv ()
  (interactive)
  (let ((nose-global-name
         (format 
          "~/.virtualenvs/%s/bin/nosetests"
          (car 
           (last 
            (delete 
             ""
             (split-string
              (nose-find-project-root)
              "/")))))))
    (nosetests-all)))
于 2013-10-15T16:50:23.130 回答