[TIP] [newbie] run nose tests contained in the current emacs buffer

meme dough memedough at gmail.com
Fri Jul 29 02:55:44 PDT 2011


Hi,

Looks like it could be a pip issue with inotifyx.  Installing from the
tgz or with easy_install works.

easy_install nosier

:)

On 29 July 2011 19:29, meme dough <memedough at gmail.com> wrote:
> Hi,
>
> An alternative tool is to use something like nosier to run the test
> file every time you save the buffer.
>
> nosier --path=tests/ --no-initial-run --with-arguments "nosetests"
>
> That will monitor all files under tests dir and whenever you save a
> test buffer it will run nosetests with the arg being the saved file.
>
> Of course you can run that in eshell so that it's in emacs ;-)
>
> Looks like inotifyx (needed by nosier) is slightly broken for
> installing with pip, but you can install by grabbing it as a tgz or
> bzr.
>
> bzr clone https://launchpad.net/inotifyx
> cd inotifyx/
> python setup.py install
>
> pip install nosier
>
> I like nosier since I wrote it and it uses the linux inotify feature
> so it is fast and not check summing files on disk.
>
> :)
>
> On 29 July 2011 10:47, Tom Roche <Tom_Roche at pobox.com> wrote:
>>
>> 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. I'm starting on 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 at it:~$ sudo easy_install nose
>> me at it:~$ pushd ~/code/python/nose/
>> me at it:~/code/python/nose$ ls -al
>>> -rw-r--r-- 1 me me   36 2011-07-28 18:47 test_me.py
>> me at 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
>>
>> https://bitbucket.org/durin42/nosemacs/src/9302529e68be/nose.el
>>
>> 2 hooked it into my init.el via
>>
>> me at 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 an emacs 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
>>
>> which looks correct. I note, when running from the (bash) shell, I get
>>
>> me at it:~/code/python/nose$ nosetests -v   -w nil -c nilsetup.cfg /home/me/code/python/nose/test_me.py
>> ... same error as above ...
>> me at 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 at 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 at 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 at it:~/code/python/nose$ nosetests -v   -w nil -c nilsetup.cfg ./test_me.py
>> ... same error as above ...
>>
>> So I'm wondering,
>>
>> 1 What should I configure to make nose.el utter the correct `nosetests` to run the nose tests contained in the current buffer?
>>
>> 2 is there a better tool for this usecase (i.e., running the nose tests in the current emacs buffer from within emacs)?
>>
>> TIA, Tom Roche <Tom_Roche at pobox.com>
>>
>> _______________________________________________
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
>> http://lists.idyll.org/listinfo/testing-in-python
>>
>



More information about the testing-in-python mailing list