unit testing - Nose/Unittest different tests dependent on Python version -


i writing a nose test api addition pandas i'm writing. use travis ci run test suites.

in version of python i'm using (python 2.7.6, numpy 1.9.2) following raises typeerror:

>>> numpy.round([1.23, 1.132], 2.5) typeerror: integer argument expected, got float 

but in version being tested against travis ci (python 2.6.9, numpy 1.9.2) same command raises warning:

>>> numpy.round([1.23, 1.132], 2.5) /home/some_user/anaconda/envs/py26/lib/python2.6/site-packages/numpy/core/fromnumeric.py:45: deprecationwarning: integer argument expected, got float   result = getattr(asarray(obj), method)(*args, **kwds) array([ 1.23,  1.13]) 

this means assertraises(typeerror) test fails.

how can write test either check typeerror or assert_produces_warning(deprecationwarning) depending on python version being tested?

there seem 2 ways this, used in pandas testing source.

there several (very similar) variants on approach:

if sys.version_info < (2, 7): 

and rather more delightful:

from distutils.version import looseversion if sys.version < looseversion('2.7'): 

which has entertaining comment in docstring:

version numbering anarchists , software realists.

i don't know of either way being preferred on other.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

qt - Passing a QObject to an Script function with QJSEngine? -

c# - Web API response xml language -