I'd appreciate help fixing a problem running `nosetests` on the nose tests in a
file within the current emacs buffer. I'm new to nose and fairly new to python,
but have been coding awhile and using emacs forever, but don't know enough
elisp to debug the code in question. I'm starting a nose tutorial
http://ivory.idyll.org/articles/nose-intro.html
Here's the simplest nose test you can write:
def test_b():
assert 'b' == 'b'
Put this in a file called test_me.py, and then run nosetests.
on an ubuntu box with python 2.6.5, GNU Emacs 23.1.50.1, and
me@it:~$ sudo easy_install nose
me@it:~$ pushd ~/code/python/nose/
me@it:~/code/python/nose$ ls -al
-rw-r--r-- 1 me me 36 2011-07-28 18:47 test_me.py
me@it:~/code/python/nose$ nosetests -v
test_stuff.test_b ... ok
--
Ran 1 test in 0.015s
OK
But I wanna run from inside emacs, so I
1 downloaded nose.el from
https://bitbucket.org/jpellerin/nosemacs/src
2 hooked it into my init.el via
me@it:~/.emacs.d$ diff -u tlrPython.el~ tlrPython.el
...
+;;; nose support (for testing)
+(require 'nose)
+(add-hook 'python-mode-hook
+ (lambda ()
+(local-set-key \C-ca 'nosetests-all)
+(local-set-key \C-cm 'nosetests-module)
+(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-cp. 'nosetests-pdb-one)))
+
3 byte-compiled everything
4 restarted emacs
But when I open ~/code/python/nose/test_me.py in a buffer and do any of the key
sequences
C-c m
C-c .
C-c a
I get buffer=*nosetests* like the following
-*- mode: compilation; default-directory: ~/code/python/nose/ -*-
Compilation started at Thu Jul 28 20:25:55
* nosetests -v -w nil -c nilsetup.cfg /home/me/code/python/nose/test_me.py
Traceback (most recent call last):
File /usr/local/bin/nosetests, line 9, in module
load_entry_point('nose==1.1.1', 'console_scripts', 'nosetests')()
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/core.py,
line 118, in __init__
**extra_args)
File /usr/lib/python2.6/unittest.py, line 816, in __init__
self.parseArgs(argv)
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/core.py,
line 135, in parseArgs
self.config.configure(argv, doc=self.usage())
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/config.py,
line 317, in configure
self.configureWhere(options.where)
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/config.py,
line 400, in configureWhere
not a directory % path)
ValueError: Working directory nil not found, or not a directory
Compilation exited abnormally with code 1 at Thu Jul 28 20:25:56
The only difference in the *nosetests* buffer is the `nosetests` line, which is
variously
C-c m - nosetests -v -w nil -c nilsetup.cfg
/home/me/code/python/nose/test_me.py
C-c . - nosetests -v -w nil -c nilsetup.cfg
/home/me/code/python/nose/test_me.py:test_b
C-c a - nosetests -v -w nil -c nilsetup.cfg
but I note, when running from bash, I get
me@it:~/code/python/nose$ nosetests -v -w nil -c nilsetup.cfg
/home/me/code/python/nose/test_me.py
... same error as above ...
me@it:~/code/python/nose$ nosetests -v -w . -c nilsetup.cfg
/home/me/code/python/nose/test_me.py
Failure: ImportError (No module named test_me) ... ERROR
==
ERROR: Failure: ImportError (No module named test_me)
--
Traceback (most recent call last):
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/loader.py,
line 390, in loadTestsFromName
addr.filename, addr.module)
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/importer.py,
line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File
/usr/local/lib/python2.6/dist-packages/nose-1.1.1-py2.6.egg/nose/importer.py,
line 71, in importFromDir
fh, filename, desc = find_module(part, path)
ImportError: No module named test_me
--
Ran 1 test in 0.005s
FAILED (errors=1)
me@it:~/code/python/nose$ nosetests -v -w . -c nilsetup.cfg test_me.py
test_me.test_b ... ok
--
Ran 1 test in 0.004s
OK
me@it:~/code/python/nose$ nosetests -v -w . -c nilsetup.cfg ./test_me.py
test_me.test_b ... ok
--
Ran 1 test in 0.006s
OK
me@it:~/code/python/nose$ nosetests -v -w . -c nilsetup.cfg
./test_me.py:test_b
test_me.test_b ... ok
--
Ran 1 test in 0.006s
OK