-
Notifications
You must be signed in to change notification settings - Fork 39
when @parametrize finds a fixture_ref in its argvalues, the parameter is not anymore accessible through request.getfixturevalue
#146
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
Comments
I should note that I was able to use the follow to accomplish what I was looking for:
I didn't change anything in the case_ functions. While this works, it would be cool to have similar functionality for @parametrize_with_cases by having an option to prevent packing or union etc. |
Hi @TheCaffinatedDeveloper , I am not sure to understand what the actual issue is. So that is why you have for example If you compare the lists you should see that no name disappeared, only new names appeared. Let me know if this is not the case. |
@smarie Thank you for your reply. That definitely makes sense. To clarify my example, if you print a list of fixtures using Even further, if you were use request.getfixturevalue('important_value') it would say that the fixture does not exist. Again, this is only when a case_ is using a fixture_ref. |
Thanks @TheCaffinatedDeveloper for this example ! I did not know about repl.it, quite cool :) I copy the examples here for reproducibility from pytest_cases import parametrize_with_cases
def case_without_fixture():
important_value = 1
other_important_value = 2
return important_value, other_important_value
@parametrize_with_cases("important_value,other_important_value", cases='.')
def test_case_without_fixture(request, important_value, other_important_value):
# important_value and other_important_value are here no problem
value = request.getfixturevalue('important_value').get()
assert value == 1
assert other_important_value == 2 and from pytest_cases import parametrize_with_cases
def case_with_fixture(some_fixture):
important_value = some_fixture
other_important_value = 2
return important_value, other_important_value
@parametrize_with_cases("important_value,other_important_value", cases='.')
def test_case_with_fixture(request, important_value, other_important_value):
value = None
try:
value = request.getfixturevalue('important_value').get()
except:
print('Fixture not found :(')
assert value == important_value
assert important_value == 1
assert other_important_value == 2 I think that there is a small misunderstanding here: |
@smarie Thanks, glad you found REPL.it useful 👍 |
Trying to reformulate this ticket in order to leave it open: when Minimal example: from pytest_cases import parametrize, fixture, fixture_ref
@parametrize("a", [1])
def test_without_fixture_ref(request, a):
print(request._fixture_defs)
assert request.getfixturevalue('a') == 1
@fixture
def some_fixture():
return 1
@parametrize("a", [fixture_ref(some_fixture)])
def test_with_fixture_ref(request, a):
print(request._fixture_defs)
assert request.getfixturevalue('a') == 1 This is due to the fact that So the second test is equivalent to @fixture
def some_fixture():
return 1
@fixture
def test_with_fixture_ref_a(some_fixture):
return some_fixture
def test_with_fixture_ref(request, test_with_fixture_ref_a):
a = test_with_fixture_ref_a
print(request._fixture_defs)
assert request.getfixturevalue('a') == 1 I'm afraid there is no simple solution to this problem... I suggest to close as "won't fix" except if you feel that this should be tackled. In that case we'll leave it open for community support |
request.getfixturevalue
Hi again @smarie!
Trying to figure out how to maintain the return values from cases that use a fixture as their own fixture name.
Example
conftest.py
mock_test.py
expected: [request, ..., ..., important_value, other_important_value, ...]
actual: [request, ..., ..., test_some_test_important_value_other_important_value, ...]
Note: this only happens when I use a fixture on the case.
The text was updated successfully, but these errors were encountered: