Skip to content

Instantly share code, notes, and snippets.

@bobjansen
Created October 20, 2012 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobjansen/3923840 to your computer and use it in GitHub Desktop.
Save bobjansen/3923840 to your computer and use it in GitHub Desktop.
Run nosetests from any directory in your virtualenv (Windows compatible)
(defun run-tests ()
"Finds the virtualenv bin-dir and run nosetests"
(interactive)
(let ((bin-dir (if (eq system-type 'windows-nt) "Scripts" "bin"))
(cwd (reverse (split-string default-directory "/"))))
(let ((venv-dir (if (string= (first cwd) "")
(find-bin-dir (rest cwd) bin-dir)
(find-bin-dir cwd bin-dir))))
(if venv-dir
(let ((old-path (getenv "PATH")))
(setenv "PATH" (concat venv-dir ";" old-path))
(compile "nosetests")
(setenv old-path))
(message "Virtualenv not found")))))
(defun find-bin-dir (path target)
"Move up the dir tree looking for a virtualenv bin-dir"
(let ((test-path
(mapconcat 'identity (append (reverse path) (list target)) "/")))
(if (file-exists-p test-path)
test-path
(if (not (eq (rest path) nil))
(find-bin-dir (rest path) target)
nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment