Skip to content

During pytest, with db() does not use test db #30

Description

@buddha314

With the standard FastAPI test_db fixture, using

# service.py 

def print_my_object():
  with db():
    return x = models.MyObject().first()
    print(x)
# test.py
def test_printing(test_db, # <- the fixture
                           test_object # <- loads the object into the db
):
  retval = service.print_my_object
  assert retval is not None

fails. The service is not a route. How do I get the test_db into the service during testing?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions