Q&A
How do you handle auth token refresh in long-running API test suites?
Ajitesh MohantaAmbassador
2w ago 794 0
Our auth tokens expire after 1 hour. Most CI runs complete in 30–40 minutes so it's fine, but nightly full-suite runs take 90+ minutes and start failing halfway through with 401s.
Current workaround: generate a fresh token at the start of each test module. Slow but reliable.
Is there a cleaner pattern — like a fixture that automatically refreshes a token when it's close to expiry? Or a session-scoped fixture that monitors expiry and renews in the background? We're using pytest.