Professor
Professor

Reputation: 101

pytest fixture yield returns generator instead of object

I'm running pytest-3. I'm defining a fixture that is supposed to return a falcon TestClient object. I also need a teardown, so I'm trying to yield it.

def client():
    api=create_app()
    c = testing.TestClient(api)
    yield c
    remove_db()

If I 'return' instead of 'yield', the test cases run just fine. But with yield, my test cases get a generator object instead of a TestClient object

Upvotes: 5

Views: 6643

Answers (1)

Amit
Amit

Reputation: 20456

Probably because the function is not marked as a fixture. Try after decorating the function with @pytest.fixture. For example,

@pytest.fixture(scope="session")
def client():
    api=create_app()
    c = testing.TestClient(api)
    yield c
    remove_db()

Upvotes: 4

Related Questions