-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Independent parameter #31
Comments
I am not sure that I understand what you wish to do here. Is this that you wish to reuse parameters for multiple tests ? Or that you dislike the |
No no, I like parametrize, but it injects the parameter for the specific test or fixture it is decorating.
That`s it, or reuse it in a fixture and a test, which is the first two code snippets I presented, which you can already do today. But what I can't do is have that for parametrizing a pair/triple/n-uple of parameters. |
I see. Well yes I guess that the answer to your need is indeed a "parameter fixture" as you show. We could imagine a |
I managed to implement it but in case of several parameter names, I had to create a "root" fixture above all parameters. Anyway it works as expected, I'll ship 1.5.0 so that you can give it a try. Here is an example: # create a single parameter fixture
my_parameter = param_fixture("my_parameter", [1, 2, 3, 4])
@pytest.fixture
def fixture_uses_param(my_parameter):
return my_parameter
def test_uses_param(my_parameter, fixture_uses_param):
# check that the parameter injected in both is the same
assert my_parameter == fixture_uses_param
# -----
# create a 2-tuple parameter fixture
arg1, arg2 = param_fixtures("arg1, arg2", [(1, 2), (3, 4)])
@pytest.fixture
def fixture_uses_param2(arg2):
return arg2
def test_uses_param2(arg1, arg2, fixture_uses_param2):
# check that the parameter injected in both is the same
assert arg2 == fixture_uses_param2
assert arg1, arg2 in [(1, 2), (3, 4)] |
Note: may I kindly ask you to support these new features into the main |
Thanks, I will check it out (and probably make an issue if I find anything wrong)! And sure I also believe this should eventually get into pytest itself, as many people are using this pattern of creating fixture parameters and this makes it more explicit. |
perfect! let me know |
Hi, this is a feature suggestion, which I believe is the missing piece of parametrization
We can define an individual parameter used for parametrization that is not either intrinsically tied to a fixture or test function like this:
The example above is bad because we are using a fixture to mask what is really a parameter. But we can solve this by doing:
and then the test becomes:
And we can use many parameters to have a cartesian product, etc etc. This still has two problems though:
parameter("my_parameter", [1,2,3,4])
instead ofmy_parameter = parameter([1,2,3,4])
parameter("my_parameter1, my_parameter2", [(1,2),(3,4)])
.So, the feature proposal would be to have this parametrization ability through the module body with the mentioned syntax:
Is this even possible? I know very little about how parametrization works under the hood in pytest, so if you might be not interested in this feature, I would appreciate some pointers.
thanks!
The text was updated successfully, but these errors were encountered: