I am writing unit tests for a function that takes both an argument *argsand a **kwargs. A reasonable use case for this function is to use the keyword arguments after the segment *args, i.e. the form
def f(a, *b, **c):
print a, b, c
f(1, *(2, 3, 4), keyword=13)
Now it has only become legal in Python 2.6 ; in earlier versions, the above line is a syntax error and therefore does not even compile into bytecode.
My question is: . How can I test the functionality provided in the new version of Python and still run tests for older versions of Python?
I must point out that the function itself works fine for earlier versions of Python, only some calls are syntax errors before Python 2.6. The various methods that I saw for checking the version of Python do not work for this, since it does not go through the compilation stage.
I would prefer not to split the tests into multiple files, if at all possible.
source
share