1. Jason Pellerin
  2. nosemacs
  3. Issues
Issue #1 invalid

can't run nose tests contained in the current buffer

Tom Roche
created an issue

I'm starting the nose tutorial http://ivory.idyll.org/articles/nose-intro.html {{{

!english

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 {{{

!bash shell

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$ cat test_me.py def test_b(): assert 'b' == 'b' 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

cut'n'pasted

https://bitbucket.org/jpellerin/nosemacs/src/0192bf439dc9/nose.el into a nose.el in my emacs site-lisp

hooked nose.el into my init.el (code below, since this @#$%^&! editor hoses on code inside a list!)

byte-compiled everything

restarted emacs

Re item 2 above: my init.el loads my tlrPython.el, which has {{{

!bash shell

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))) + }}} But when I open $HOME/code/python/nose/test_me.py in a buffer and do any of the key sequences {{{

!english

C-c m C-c . C-c a }}} I get buffer=nosetests like the following {{{

!emacs buffer

-- mode: compilation; default-directory: "~/code/python/nose/" -- Compilation started at Thu Jul 28 21:20:04

nosetests -v -w nil -c nilsetup.cfg /home/me/code/python/nose/test_me.py:test_b 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 21:20:05 }}} The only difference in the nosetests buffer is the nosetests line, which is variously {{{

!english

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 {{{

!bash shell

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 me@it:~/code/python/nose$ nosetests -v -w nil -c nilsetup.cfg ./test_me.py ... same error as above ... }}} Shouldn't something this simple Just Work, Out Of The Box? Or am I misconfiguring? Or missing something else entirely?

Comments (1)

  1. Jason Pellerin repo owner

    This happens when nose.el can't find the project's root directory. By default it looks back from dir containing the current file to /, looking for setup.py, .hg or .git -- wherever it finds one of those is considered the project root. You can modify the files it looks for by modifying nose-project-root-files, or change the test used to determine whether a directory is the project root by setting nose-project-root-test.

  2. Log in to comment