-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow parametrize to bubble up the fixture chain #4496
Comments
that kind of bubbling is absolutely unacceptable - it would make the fixture system more error prone to use and more error prone to implement the correct way is to parametrize the fixture you actually want to hand a parameter to |
You mean, to use: |
@brunoais no - i mean using the name of the fixture that is supposed to get the parameters instead of the name of a fixture that uses it indirectly when using parameterize |
That doesn't work either because (using the names in the example) Imagine as if it was this (incomplete-code)
|
@brunoais that example is fundamentally broken a) if there was more than one fixture used we wouldn't know which one to bubble up also the example you showed would directly work right now by using |
You mean, making
? |
In the end, I was just doing it wrong. I should have done like this in the first place:
-> I'll try finding the time to create an example for the documentation.... Such unfortunate that I didn't think about that possibility. Oh well... My problem is then solved. |
Note: I don't know if this is a bug or a feature I'd like to have.
What I want:
When parametrizing a test (
@pytest.mark.parametrize()
withindirect=True
, all fixtures in the "bubbling chain" that userequest.param
receive the parameters that were set by the test.Example (which now fails):
The code fails at
return request.param * 2
.AttributeError: 'SubRequest' object has no attribute 'param'
Tried workarounds:
indirect=['test_fixture', 'higher_stage_test_fixture']
, ofc, didn't work. The system requires that all values in indirect are specified as function parameters (first parameter inparametrize
).1.1 Adding the parameter in the function didn't work (see 1.1.1)
1.1.1. Adding the parameter in
parametrize
@pytest.mark.parametrize(['higher_stage_test_fixture', 'test_fixture']
... as expected, was futile.Due to how parameterization is organized and prepared, changing that algorithm would be a huge loss in time.
Which lead to
Nasty-looking working workaround:
There is code elsewhere calling
higher_stage_test_fixture
directly, for other tests. So it can't easily be changed now.The workaround 2 does its job but it seems like going around a measure that was built not to happen (for good reason, the cannot call fixtures directly exception exists)
So, how can I "bubble up" the parametrization of test_function up to higher_stage_test_fixture without the nasty workaround?
Thanks in advance...
I thought this could be related to #460 but it seems to have some differences in the details of the call chain
The text was updated successfully, but these errors were encountered: