Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Error using parametrize with default arguments #3221
With pytest 3.4.0:
import pytest @pytest.mark.parametrize("something", [True, False]) def test_something(something=False): pass
You get the error:
It seems pytest is separating the concept of normal python arguments and 'fixtures' here, only classifying only default-free arguments as potential fixtures - and then only considering 'fixtures' as valid targets for parametrisation - but the error message completely obfuscates this: by any regular python interpretation the function definitely has an argument 'something'.
The documentation on this - https://docs.pytest.org/en/latest/parametrize.html doesn't show this as an example but also doesn't mention that it's a constraint; it's only through reading the pytest source that I could work out what the problem was.
Related: The wording of this was changed to 'argument' from 'fixture' in #1539 which makes sense in the context of that error, but only confuses this one.
Yes, that is the root cause. But this isn't a question; my point is that the error is completely confusing and the solution non-obvious unless you read the source code:
and then complains that there is no argument.
So I'd consider it either a bug with error messages, argument-as-potential-fixture classification (although I assume this was rigorously discussed in the past and is like this for a reason), or a documentation problem.