-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add public API to get value of fixture by its name #11944
Comments
the it was never valid to make a external instance of FixtureRequest please outline the usecase |
Maybe I am unaware of different possibilities to get value of any fixture at hook level. Are there any? |
There is no way to just get fixtures at the hook level Doing so is likely to compromise the consistency of the setup state and worked by accident |
Yeah, but worked and was very practical in my usecase ;) Access to fixtures
at hook level could be very handy
śr., 7 lut 2024, 18:01 użytkownik Ronny Pfannschmidt <
***@***.***> napisał:
… There is no way to just get fixtures at the hook level
Doing so is likely to compromise the consistency of the setup state and
worked by accident
—
Reply to this email directly, view it on GitHub
<#11944 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVR4OCFUJJTIIIAH7ZFHMSTYSOXOTAVCNFSM6AAAAABC5Z3AKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGQ4DSNRTGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
How does the |
Something like this: from typing import Iterator
from pytest import fixture
from selenium.webdriver import Chrome
@fixture
def driver() -> Iterator[Chrome]:
driver_ = Chrome()
yield driver_
driver_.quit() |
I have another use-case for this. It’s about committing all the database model instances created in fixtures to the database in one go before invoking the test method: https://stackoverflow.com/a/56013856 |
Closing this as duplicate of #2471. 👍 |
What's the problem this feature will solve?
In lower version, it was possible to perform sth like this:
With pytest 8.0 this is not possible because FixtureRequest is abstract. Public API to get value of fixture would mitigate this problem.
Describe the solution you'd like
The best will be to add method to
Item
|Function
to get fixture value. Alternatively will be to add similar API somewhere in_pytest.fixtures.py
and reexport it inpytest.__init__.py
Ability to get value from fixture by its name would be really useful to perform actions which requires fixture at hook level. In my example, I am using
driver
fixture to passselenium
WebDriver
to tests. After test teardown I am taking screenshot if test was failed atpytest_runtest_makereport
scope. Lack of available API at pytest level makes it impossible to get fixture if error happens atsetup
(driver
is not present atitem.funcargs
:Alternative Solutions
Missing. All code to inspect fixtures is hidden under private API (in
_pytest
)The text was updated successfully, but these errors were encountered: