pylint or similar to test version-specific language constructs?

Dave Angel d at davea.name
Fri Jan 11 11:09:15 EST 2013


On 01/11/2013 10:37 AM, Steven D'Aprano wrote:
> On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote:
>
>> <snip>
>
>> Not sure what you mean by beforehand.  Don't you run all your unit tests
>> before putting each revision of your code into production?  So run those
>> tests twice, once on 2.7, and once on 2.4.  A unit test that's testing
>> code with a ternary operator will fail, without any need for a separate
>> test.
> You don't even need tests for the code that includes the ternary 
> operator. The module simply won't compile in Python 2.4, you get a 
> SyntaxError when you try to import it or run it.
>
> You don't need PyLint to check for *illegal syntax*. Python already does 
> that.
>

You're right of course.  But I can weasel out of it by saying that
Python will only check it if the particular module is imported.  I've
seen equivalent bugs in real projects, where a release went out with one
of its dynamic libraries not even present.

Another thing that can stop Python from checking is if some naive
programmer uses a bare except in production code.

Both of these would show up in the simplest of unit testing code.



-- 

DaveA




More information about the Python-list mailing list