I'm writing unit tests for a function that takes both an *args
and a **kwargs
argument. A reasonable use-case for this function is using keyword arguments after the *args
argment, i.e. of the form
def f(a, *b, **c):
print a, b, c
f(1, *(2, 3, 4), keyword=13)
Now this only became legal in Python 2.6; in earlier versions the above line is a syntax error and so won't even compile to byte-code.
My question is: How can I test the functionality provided in the newer Python version and still have the tests run for older Python versions?
I should point out that the function itself works fine for earlier Python versions, it is only some invocations that are syntax errors before Python 2.6. The various methods I've seen for checking the Python version don't work for this as it doesn't get past the compilation stage.
I would prefer not to have to split the tests into multiple files if at all possible.