7

Is there a library which of nose-friendly assertions things like membership and identity (eg, assert_contains(x, y), assert_is(a, b))?

David Wolever
  • 148,955
  • 89
  • 346
  • 502

2 Answers2

10

Nose provides stand-alone versions of the stdlib assertions:

from nose.tools import assert_in, assert_is

For older Pythons, the unittest2 versions can likely be wrapped using a technique similar to what's in tools.py.

jek
  • 116
  • 3
  • Aahh, so it does. Apparently I've been missing that little paragraph at the top of the tools documentation all these years… Thanks. – David Wolever Jan 16 '11 at 06:29
  • Hhmm… They don't exist for me, but like you mention, I suspect that's because I'm "only" using 2.6. I've gone ahead and written a `nose` patch which will try to use unittest2 assertions, if they are available: http://code.google.com/p/python-nose/issues/detail?id=392 – David Wolever Jan 16 '11 at 07:35
3

Stdlib unittest provide both assertIn and assertIs and can be run via nose. Are you looking for something other than that? BTW, these methods are available since python 2.7 only and if you want them for older version of python, it is available from unittest2 package

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
  • 3
    I don't like the built-in assertions because I don't find the strict xUnit style plays well with Python: the `self.` prefix on all assertions is not so much fun, and `camelCase` makes everything look weird. – David Wolever Jan 16 '11 at 05:43
  • Oh I see. It is a matter of preference then. Certain modules/libraries have certain styles. AFAIK, you cannot do way with self part in unittest, you can alias the camelCase thing to something which you will prefer. – Senthil Kumaran Jan 16 '11 at 06:00