vendredi 24 juin 2016

How to unit test a python version switch

How can I write a unit test for the following function:

def version_switch():
    if sys.version_info.major < 3:
        print('not python 3')
    else:
        print('python 3')

My first thought was mocking sys.version_info.major but as it is a read only attribute it will not do.

To be sure: I do run my test suite under py3 and py2 using tox. however, each run will only check one code path. The actual function does not use any language specific features. Should I look for alternative ways to determine the version, ones that are easier to mock?

Aucun commentaire:

Enregistrer un commentaire