Reputation: 101
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
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