-
-
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
No API to request fixtures from pytest.Item #2471
Comments
That's a little clumsy I agree. Unfortunately I'm not sure we want to expose the current fixture API as official right now, given that time and time again we mention that this part of the code could use some refactoring... |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
No worries! I for one definitely appreciate your periodic triage of the issue tracker. We also try to find the right balance, don't worry. And we can always re-open an issue if we find that's the correct course of action. |
I just ran into this issue. I want to use some functionality that's only available in fixtures (namely, capture logs) inside a test implemented as |
Some fallout from #11868:
What's the current state on:
Given that IIRC we had a lot of refactorings to fixture implementations recently? @bluetech @sadra-barikbin |
the large, awesome and numerous refactorings @bluetech and @sadra-barikbin poured in over the last few months, i'm still very terrified of opening the api up, as i'm aware of a lot of the backlogs and pains ever since the 2016 sprint |
While I share that fear, we probably don't need/should not just open the API, we can probably start small with functions/methods which are based on pytest's external design, rather than exposing implementation details. Just an example from the top of my head, we could introduce a method to |
@cjw296 Can you describe what "request fixtures from pytest.Item" means? It is not very clear. I assume it's not literally requesting a fixture, since |
@bluetech i believe it relates to the initially linked code dealing with non-python items as far as fixture configuration, parameterization and state management is concerned, a lot of it is has so far primarily stuck on python details |
Right, I'm mostly interested to know which fixture functionality these non-python items want to use (i.e. use cases), and what they currently implement using the pytest internals. |
The initially linked code shows what they do |
@bluetech - ultimately, I need to do this:
...but to do that, I currently need to do this: ...and then this: If there's a better, more supported way to do this, I would love a PR to show me how! |
What is |
The instance of whatever the fixture is. For example, if this were a normal pytest function: def test_foo(bar: Baz) -> None:
... ...then |
A note: while supporting basic fixtures is one thing and probably possible, supporting parametrization will be quite a bit more difficult. Even for pytest's own doctests it's broken -- the following errors out: import pytest
@pytest.fixture(autouse=True, params=[1, 2])
def number(request, doctest_namespace):
doctest_namespace["number"] = request.param
def func():
"""
>>> number < 10
True
""" |
I think it is OK to only support basic fixtures initially, with an error if a parametrized fixture is requested. This will probably already cover the majority of cases. |
+1 for adding this API |
The function definition type needs to be hoisted into nodes |
It made me a bit sad that I had to c'n'p this piece of code, rather than call a helper, to request fixtures in an Item subclass:
https://github.com/cjw296/sybil/blob/552d3ff2d6e8639ee5d3c8efa26f5e535e064ae8/sybil/integration/pytest.py#L41
The text was updated successfully, but these errors were encountered: