[TIP] unittest version info
fuzzyman at voidspace.org.uk
Thu Sep 9 08:01:11 PDT 2010
On 09/09/2010 12:07, Julien Jehannet wrote:
> Hello TIP,
> In order to move old testlib assertion methods to new (standard)
> unittest2 incarnations, I would retrieve unittest info installed
> in my system.
> But I can't find any attribute to rely on. And __version__ was quite
> confusing at the moment.
> % python2.5 -c 'import unittest; print unittest.__version__'
> % PYTHONPATH=unittest2 python2.5 -c 'import unittest2 as unittest; print unittest.__version__'
> 0.6.0 alpha (plugins branch)
> % python3.1 -c 'import unittest; unittest.__version__'
> Traceback (most recent call last):
> File "<string>", line 1, in<module>
> AttributeError: 'module' object has no attribute '__version__'
> Is there a standard way to detect unittest flavour ?
The __version__ number in unittest is something I haven't maintained, so
it is my fault that it doesn't make sense.
*However*, there is little point in it containing anything other than
the Python version number as unittest APIs change at least slightly with
every major release.
So... the simple rule is that if you have unittest then use the Python
version, if you have unittest2 then you can trust its __version__
attribute. You can tell if you have unittest2 because there will be
'unittest2' somewhere in __file__ for the unittest2 modules. (And also
because you imported it...)
> If not yet, may I suggest to have similar convention that the sys module¹ ?
> - a __version__ string module attribute (which should be>2.X IMO)
> - but also a __version_info__ tuple containing the separated fields
> __version_info__ = tuple([int(num) for num in __version__.split('.')])
> The only interest here is to ease version comparaison afterwards.
> Note: maybe it can be worth to follow PEP-0386² for string version
> convention (i.e. no space for example)
> Best Regards,
> ¹ http://docs.python.org/library/sys.html#sys.version_info
> ² http://www.python.org/dev/peps/pep-0386/
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies ("BOGUS AGREEMENTS") that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python