Fri Aug 4 20:49:32 2006

Ticket #80 (Closed: worksforme)

provide TestCase methods as functions.


Priority: normal Reporter: jorge.vargas
Severity: enhancement Assigned to: jpellerin
Component: nose Status: closed
Version: 0.9 Resolution: worksforme
Milestone: 1.0 Keywords: Exceptions nose TestCase

Description by jorge.vargas:

Hi

First of all I'm new to nose and I like what I see, I always complained about JUnit/pyUnit because it's too much troubles ... nose takes that away from me.

but when I try to test for a method that should raises a certain type of exception I found out that the only way to do this is with TestCase, at least to catch a certain specific type of test.

So how abotu adding a reimplementation (basically transform the methods into functions of TestCase.* into module level nose functions?

So we can implement this

class TestMyApp(TestCase):
    def test_create(self):
        self.failUnlessRaises(NotImplementedError, source.create)

as

def test_create():
    nose.failUnlessRaises(NotImplementedError, source.create)

here is the original thread. http://tinyurl.com/mvssg

Changelog

Fri Aug 4 22:31:39 2006: Modified by jpellerin

  • resolution set to worksforme
  • status changed from new to closed

Check out nose.tools.raises, I believe that will do what you want. It's a decorator that you use like so:

import nose.tools

@nose.tools.raises(NotImplementedError)
def test_something():
    ...

Fri Aug 4 23:25:17 2006: Modified by jorge.vargas

    ohh thanks for your quick reply, I didn't saw any reference to that module on the docs.

    I'll make a wiki entry.

    Fri Aug 4 23:41:13 2006: Modified by guest

      posted at http://nose.python-hosting.com/wiki/Tips

      thanks again, and keep up the good work!