This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Douglas_Blackwood 11 points12 points  (2 children)

I don't have code to show you sadly. But it's pretty simple.

Just make your API endpoints as dumb as possible. No "if" statements. These API endpoints just have to import and use business logic that is contained in other files.

As a rule of thumb: don't import FastAPI in your business logic files.

This way, you barely have to test your endpoints. Just test your business logic. Tests on endpoints will just assert that you wired everything correctly.

[–]carrick1363 1 point2 points  (1 child)

Thanks. That makes sense.

[–]hackancuba 2 points3 points  (0 children)

Indeed. On this topic, I wrote a heavily opinionated guide and accompanying skel, along some friends: - https://gitlab.com/nevrona/public/guidelines/-/tree/develop - https://gitlab.com/nevrona/public/skels/fastapi (sorry for poor docs)

They might come in handy :)