Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest fixture returning multiples

Tags:

python

pytest

Is it possible to have a fixture that returns a dictionary and dataframe?

import somefile
import pytest

@pytest.fixture()
def setup():
    dictionary, dataframe = somefile.get_Di_And_Df()
    return(dictionary, dataframe)

def test_check(setup):
    assert dictionary['movie']['action'] == 'Avengers'
    assert dataframe.shape[0] == 5
like image 279
curiousgeorge Avatar asked Aug 03 '26 07:08

curiousgeorge


1 Answers

The return value (or yield value) of the fixture is literally the object injected as a function argument during test execution:

def test_check(setup):
    dictionary, dataframe = setup
    assert dictionary['movie']['action'] == 'Avengers'
    assert dataframe.shape[0] == 5
like image 71
wim Avatar answered Aug 05 '26 21:08

wim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!