emboole
emboole

Reputation: 561

PyTest: ValueError: did not yield a value

I just created a pytest fixture and i can't use yield, since it gives me an error I tried different stuff without success.

What i'm doing wrong?

@pytest.fixture
def names_resp():
    with open('ropo_resp.json', 'r') as names:
        global data
        data = json.load(names)
        return data
    
    yield
    print("a")

Upvotes: 1

Views: 2166

Answers (1)

Guy
Guy

Reputation: 50819

Your fixture is expecting to yield something, even if it's None. But your yield is unreachable since you have return before it

@pytest.fixture
def names_resp():
    with open('ropo_resp.json', 'r') as names:
        data = json.load(names)
    yield data
    print("a")

Upvotes: 1

Related Questions