Commits

Tom Davis committed ceda97b

Use relative paths to test files to fix fixture discovery.

When we cd to the project directory then supply the full root path to
tests (in the case of pytest-run-module, etc.) pytest gets confused and cannot
find custom fixtures.

  • Participants
  • Parent commits e704497

Comments (0)

Files changed (1)

 ;; In your emacs config:
 ;;
 ;;   (require 'pytest)
-;; 
+;;
 ;; If you don't use a global installation of py.test (ie in
 ;; virtualenv) then add something like the following that points to
 ;; either the non-global version or a test runner script.:
 ;;
 ;;   (add-to-list 'pytest-project-names "my/crazy/runner")
-;; 
+;;
 ;; You can generate a script with py.test:
 ;;
 ;;   py.test --genscript=run-tests.py
 
-;; Another option is if your global pytest isn't called "pytest" is to 
+;; Another option is if your global pytest isn't called "pytest" is to
 ;; redefine pytest-global-name to be the command that should be used.
 
 ;; By default, the root of a project is found by looking for any of the files
 
 (defcustom pytest-cmd-flags "-x"
   "These are the flags passed to the pytest runner")
-  
+
 (defun run-pytest (&optional tests flags)
   "run pytest"
   (virtualenv-hack-dir-local-variables)
   (let* ((pytest (pytest-find-test-runner))
          (where (pytest-find-project-root))
-         (tnames (if tests tests ""))
-	 (cmd-flags (if flags flags pytest-cmd-flags)))
+         (tnames (if tests (mapconcat (lambda (test) (substring test (string-width where)))
+                                      (split-string tests) " ") ""))
+         (cmd-flags (if flags flags pytest-cmd-flags)))
     (funcall '(lambda (command)
-		(compilation-start command nil
-				   (lambda (mode) (concat "*pytest*"))))
-	     (format "cd %s && %s %s %s"
-		     where (pytest-find-test-runner) cmd-flags tnames))))
+                (compilation-start command nil
+                                   (lambda (mode) (concat "*pytest*"))))
+             (format "cd %s && %s %s %s"
+                     where (pytest-find-test-runner) cmd-flags tnames))))
 
 ;;; Run entire test suite
 (defun pytest-all (&optional flags)
 (defun pytest-directory (&optional flags)
   "run pytest on all the files in the current buffer"
   (interactive)
-  (run-pytest (file-name-directory buffer-file-name) flags)) 
+  (run-pytest (file-name-directory buffer-file-name) flags))
 
 (defun pytest-pdb-directory (&optional flags)
   "run pytest on all the files in the current buffer"
   "Run the tests interactively asking for the test flags and
 file/dir"
   (interactive)
-  (let ((tests (expand-file-name 
-		(read-file-name "Test directory or file: "
-				(pytest-current-root))))
-	(flags (read-from-minibuffer "py.test flags: ")))
+  (let ((tests (expand-file-name
+                (read-file-name "Test directory or file: "
+                                (pytest-current-root))))
+        (flags (read-from-minibuffer "py.test flags: ")))
     (run-pytest tests flags)))
 
 
 ;;; Utility functions
 (defun pytest-find-test-runner ()
   (let ((result
-	 (reduce '(lambda (x y) (or x y))
-		 (mapcar 'pytest-find-test-runner-names pytest-project-names))))
+         (reduce '(lambda (x y) (or x y))
+                 (mapcar 'pytest-find-test-runner-names pytest-project-names))))
     (if result
-	result
+        result
       pytest-global-name)))
 
 (defun pytest-find-test-runner-names (runner)