Skip to content

Commit

Permalink
Add support for test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Apr 7, 2014
1 parent 74e23b5 commit faec939
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ What's different ?
This fork:
- brings Windows compatibility.
- calls python with an inline script to launch nose.

I also plan to make it work with test suites (available via
`easy_install nose-fixes`).
- can launch test suites (require to install the nose fixes via
`easy_install nose-fixes`)

Install
-------
Expand All @@ -28,8 +27,8 @@ Usage
-------

By default, the root of a project is found by looking for any of the files
`setup.py`, `.hg` and `.git`. You can add files to check for to the file
list:
`setup.cfg`, `.hg`, `.git` and `.projectile`. You can add files to check
for to the file list:

(add-to-list 'nose-project-root-files "something")

Expand All @@ -42,17 +41,37 @@ If you want dots as output, rather than the verbose output:

(defvar nose-use-verbose nil) ; default is t

Probably also want some keybindings:
Probably also want some key bindings:

(add-hook 'python-mode-hook
(lambda ()
(local-set-key "\C-ca" 'nosetests-all)
(local-set-key "\C-cm" 'nosetests-module)
(local-set-key "\C-cs" 'nosetests-suite)
(local-set-key "\C-c." 'nosetests-one)
(local-set-key "\C-cpa" 'nosetests-pdb-all)
(local-set-key "\C-cpm" 'nosetests-pdb-module)
(local-set-key "\C-cps" 'nosetests-pdb-suite)
(local-set-key "\C-cp." 'nosetests-pdb-one)))

Notes
------

To be able to launch a test suite, your suite must define a function with
the name `load_tests`.

For instance (typical example to make `PyDev` *and* `nose.el` happy):

import unittest

ALL_TESTS = unittest.TestSuite([my_suites_go_here])

def load_tests(loader=None, tests=None, pattern=None):
return ALL_TESTS

if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(ALL_TESTS)

Thanks
------

Expand Down
28 changes: 21 additions & 7 deletions nose.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
;; python with an inline script to call nose.

;; By default, the root of a project is found by looking for any of the files
;; 'setup.py', '.hg' and '.git'. You can add files to check for to the file
;; '.projectile', 'setup.cfg', '.hg' and '.git'. You can add files to check for to the file
;; list:
;;
;; ; (add-to-list 'nose-project-root-files "something")
Expand All @@ -54,11 +54,14 @@

(require 'cl) ;; for "reduce"

(defvar nose-project-root-files '("setup.py" ".hg" ".git"))
(defvar nose-project-root-files '(".projectile"
"setup.cfg"
".hg"
".git"))
(defvar nose-project-root-test 'nose-project-root)
(defvar nose-use-verbose t)

(defun run-nose (&optional tests debug failed)
(defun run-nose (&optional tests suite debug failed)
"run nosetests by calling python instead of nosetests script.
To be able to debug on Windows platform python output must be not buffered.
For more details: http://pswinkels.blogspot.ca/2010/04/debugging-python-code-from-within-emacs.html
Expand All @@ -67,7 +70,9 @@ For more details: http://pswinkels.blogspot.ca/2010/04/debugging-python-code-fro
(where (nose-find-project-root))
(args (concat (if debug "--pdb" "")
" "
(if failed "--failed" "")))
(if failed "--failed" "")
" "
(if suite "--test-suite-func=load_tests" "")))
(tnames (if tests tests "")))
(if (not where)
(error
Expand All @@ -89,7 +94,7 @@ For more details: http://pswinkels.blogspot.ca/2010/04/debugging-python-code-fro
(defun nosetests-all (&optional debug failed)
"run all tests"
(interactive)
(run-nose nil debug failed))
(run-nose nil nil debug failed))

(defun nosetests-failed (&optional debug)
(interactive)
Expand All @@ -102,17 +107,26 @@ For more details: http://pswinkels.blogspot.ca/2010/04/debugging-python-code-fro
(defun nosetests-module (&optional debug)
"run nosetests (via eggs/bin/test) on current buffer"
(interactive)
(run-nose buffer-file-name debug))
(run-nose buffer-file-name nil debug))

(defun nosetests-pdb-module ()
(interactive)
(nosetests-module t))

(defun nosetests-suite (&optional debug)
"run nosetests (via eggs/bin/test) on current suite buffer"
(interactive)
(run-nose buffer-file-name t debug))

(defun nosetests-pdb-suite ()
(interactive)
(nosetests-suite t))

(defun nosetests-one (&optional debug)
"run nosetests (via eggs/bin/test) on testable thing
at point in current buffer"
(interactive)
(run-nose (format "%s:%s" buffer-file-name (nose-py-testable)) debug))
(run-nose (format "%s:%s" buffer-file-name (nose-py-testable)) nil debug))

(defun nosetests-pdb-one ()
(interactive)
Expand Down

0 comments on commit faec939

Please sign in to comment.