---
title: "Give every test its own time limit · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/per-test-timeout
id: TST-59
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 743
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Give every test its own time limit

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Flaky and slow tests](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: TST-59
- Level: Recommended
- Chapter: [Flaky and slow tests](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests.md)
- Rule: Set a time limit on every single test, such as 5 seconds for unit tests and 60 seconds for browser tests. A test that runs past it fails with its name in the report.
- Check: The runner settings hold a limit for each single test. A test that awaits a promise that never settles fails within that limit, and the report names it.
- How: A test that waits forever on a lock, a socket or a promise hangs the whole run. The job limit then kills it with no test name in the log. The Node.js test runner waits forever by default, since its `timeout` option defaults to `Infinity`. Set the limit in the runner settings, such as `--test-timeout` in Node.js, `testTimeout` in Vitest and Jest, or `timeout` in Playwright. In Python, the pytest-timeout plugin fails a slow test, and the built-in `faulthandler_timeout` setting prints where it hung. The [time budget](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/suite-time-budget.md) for the whole suite stays as the outer limit.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
// vitest.config.js
export default { test: { testTimeout: 5_000, hookTimeout: 10_000 } };
```

### Python example

```python
# A hung call fails this test after 5 seconds (pytest-timeout)
@pytest.mark.timeout(5)
def test_the_export_finishes():
    assert export_orders(month="2026-09").rows > 0
```

## Sources

- [Node.js test runner](https://nodejs.org/api/test.html)
- [pytest faulthandler_timeout setting](https://docs.pytest.org/en/stable/how-to/failures.html)

## Related rules

- TST-30 [Keep the suite within a time budget](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/suite-time-budget.md) in Testing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/per-test-timeout">Agent Wranglers testing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Run the tests a change affects on every pull request](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/test-selection.md)
- [Flaky and slow tests](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests.md)
