Like this
@pytest.fixture
def myfixture():
# creates a complex object
def test_compare(myfixture,myfixture):
#compares
Is there a way to know which fixture am I working on? The generated objects are different
Thanks
Like this
@pytest.fixture
def myfixture():
# creates a complex object
def test_compare(myfixture,myfixture):
#compares
Is there a way to know which fixture am I working on? The generated objects are different
Thanks
Sardorbek Imomaliev
On
You are looking for factory pattern https://docs.pytest.org/en/latest/fixture.html#factories-as-fixtures
Here is SO question about advantages of fixture factories Why would a pytest factory as fixture be used over a factory function?
Answering your question
@pytest.fixture
def myfixture():
def _make_fixture():
# creates a complex object
return _make_fixture
def test_compare(myfixture):
data1 = myfixture()
data2 = myfixture()
#compares
Copyright © 2021 Jogjafile Inc.
Why you want to compare objects returned by fixture? Fixtures are not meant to be so.
As per the documentation,
If you want to compare returned objects, just make it as a function, not as a fixture.Like.