check for a certain Python version

U

Ulrich Eckhardt

Hi!

I'd like to give my users a meaningful error message when they are using
obsolete Python versions. Is there some kind of best practice or recipe
for that? Specifically, the case is a bunch of unittests that use
features new to Python 2.7.

Thank you!

Uli
 
R

Roy Smith

Ulrich Eckhardt said:
Hi!

I'd like to give my users a meaningful error message when they are using
obsolete Python versions. Is there some kind of best practice or recipe
for that? Specifically, the case is a bunch of unittests that use
features new to Python 2.7.
(2, 6, 1, 'final', 0)


major, minor, _, _, _ = sys.version_info
self.assertGreaterEqual(minor, 7, "You, dude, fix your python")
 
S

Steven D'Aprano

Hi!

I'd like to give my users a meaningful error message when they are using
obsolete Python versions. Is there some kind of best practice or recipe
for that? Specifically, the case is a bunch of unittests that use
features new to Python 2.7.

if sys.version < "2.7": ...


Or test for features and either provide your own, or disable
functionality not available:

class MyTest:
try:
@unittest.FancyFeature
def testFancy(self):
self.assertFancy(self, ...)
except AttributeError:
pass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,155
Messages
2,570,872
Members
47,401
Latest member
CliffGrime

Latest Threads

Top