r/FastAPI • u/AsYouAnswered • Jul 29 '25
Question End to End tests on a route?
So I'm working on tests for a FastAPI app, and I'm past the unit testing stage and moving on to the integration tests, against other endpoints and such. What I'd like to do is a little strange. I want to have a route that, when hit, runs a suite of tests, then reports the results of those tests. Not the full test suite run with pytest, just a subset of smoke tests and health checks and sanity tests. Stuff that stresses exercises the entire system, to help me diagnose where things are breaking down and when. Is it possible? I couldn't find anything relevant in the docs or on google, so short of digging deep into the pytest module to figure out how to run tests manually, I'm kinda out of ideas.
4
u/Relevant-Strength-53 Jul 29 '25
Checkout test containers. Although it needs some time for setup, you can test all your routes by creating a client fixture that when setup correctly, it can call any of your endpoints to be tested. You can even setup a real database for it that will run in docker and ofcourse it cleans it up as it is a fixture.
0
u/idkwhatimdoing069 Jul 29 '25
!remindme 24h
1
u/RemindMeBot Jul 29 '25
I will be messaging you in 1 day on 2025-07-30 03:23:02 UTC to remind you of this link
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback
1
Jul 29 '25
[removed] — view removed comment
2
u/AsYouAnswered Jul 30 '25
The context is advanced integration testing. We have a suite of fastapi instances spread around and calling each other. We have good unit tests for each, but the whole thing is still a mess of interdependencies. The main end product is a dashboard that shows all the tests are currently passing, but the use case is to be able to say "well, we changed this service, and the unit tests pass, but these three tests went red across the platform", and also when standing up a new instance of the service, to be able to hit this endpoint and say "all the paths through the code are green, we haven't missed or misconfigured anything"
2
Jul 30 '25
[removed] — view removed comment
2
u/AsYouAnswered Jul 31 '25
Oh, I wish I could talk a lot more about it. It's a really fun product, and I'm actually quite excited. But I've got NDAs all over it 😞
2
u/ManufacturerEarly565 Jul 29 '25
Not sure if it’s a great idea to couple testing within your application logic if that’s what you mean by route. You could make a single integration test path that does a lot of stuff using the out-of-box TestClient that FastAPI provides.
By stress test do you mean load test? If that’s the case you could build a locust script that runs post deployment in a staging environment that mirrors your production environment.