pytest-asyncio has no setting that guarantees faster tests. First measure where your suite spends time; if event-loop setup or async fixture setup is a meaningful cost, test a broader event-loop scope and compare results. Broader scope can reduce repeated setup, but it also means tests share more state. Keep the change only if your own suite gets faster without losing isolation.
Find out what is making the suite slow
Before changing pytest-asyncio settings, run the same test selection under the same environment several times and record the durations. Keep the test selection, dependency state, and warm or cold conditions consistent. Compare repeated runs rather than relying on one timing; report the measured result for your project instead of assuming a particular percentage improvement.
Look for repeated asynchronous setup, event-loop creation, and fixture work that runs for many tests. If the suite’s time is dominated by application work, I/O, or other test setup, changing loop scope may not help. The pytest-asyncio documentation describes configuration and behavior, but does not promise or quantify a speedup.
Try a broader event-loop scope only when it fits
pytest-asyncio 1.4.0 documentation says each async test uses its own event loop by default, and the default test-loop scope is function. Supported scopes are function, class, module, package, and session. A broader scope can avoid recreating a loop as often, but tests within that scope share it and can affect one another through loop-bound state.
#1 Best Overall
Experiment with a session-scoped test loop
For a project where loop setup is measurable, try this in pyproject.toml:
[tool.pytest.ini_options]
asyncio_default_test_loop_scope = "session"
This is an experiment, not a blanket recommendation. Run the same tests before and after, compare several runs, and check for state leakage or fixtures that assume a fresh loop. If the suite becomes flaky or relies on isolation, use a narrower scope or isolate the tests that need different loop lifetimes.
Choose scope with fixture compatibility in mind
Loop scope is a lifecycle choice as well as a potential setup-cost choice. A fixture and the tests using it need compatible loop lifetimes; widening the test loop without considering async fixtures can cause failures or hidden coupling. Change scope deliberately and consult the pytest-asyncio marker documentation for scope behavior.
| Scope | What to consider |
|---|---|
| function | Fresh loop per async test; favors isolation and is the documented default. |
| class | Tests in a class can share a loop; check class-level state and fixtures. |
| module | Tests in a module can share a loop; check for order dependence and leaked state. |
| package | Tests in a package can share a loop; validate fixture lifetimes across modules. |
| session | Tests in the session can share a loop; use only when the suite and fixtures are safe with that wider lifetime. |
Use the current guide to changing the default event-loop scope for configuration details.
Set async test discovery mode deliberately
pytest-asyncio’s current configuration documentation lists auto and strict; it says strict is the default when no mode is specified. Check the version installed in your environment and the project’s configuration rather than relying on a remembered default.
Auto mode
When the project uses asyncio alone and less explicit marking is useful, configure:
[tool.pytest.ini_options]
asyncio_mode = "auto"
In auto mode, pytest-asyncio takes ownership of asyncio tests and fixtures. The older concepts documentation describes this mode as convenient for asyncio-only projects.
Strict mode
Strict mode makes asyncio test and fixture ownership explicit, which is useful when another async framework or pytest plugin needs to coexist. The 1.4.0 configuration documentation identifies strict as the default when no mode is configured. You can also select a mode for a run with --asyncio-mode; see the configuration reference.
Best Value
Do not confuse async concurrency with parallel test execution
Async code can run concurrent tasks within an individual test, but that does not mean pytest-asyncio schedules separate test cases concurrently. Its guide says parametrized asynchronous cases still run sequentially. If a parameterized test is slow, inspect the work each case performs; parametrization itself is not a mechanism for parallelizing those cases. See the parametrization guide.
Update older event-loop customization recipes
If a project customizes event-loop creation, check whether its recipe matches current pytest-asyncio guidance. The 1.4.0 multiple-loop guide marks overriding event_loop_policy as deprecated and recommends the pytest_asyncio_loop_factories hook instead. Do not copy an older customization without checking the current multiple-loops guide.
Troubleshoot a scope or mode change
- Tests fail after widening scope: Look for loop-bound objects, mutable state, or fixtures that assumed a fresh loop. Restore a narrower scope, or restructure setup so sharing is safe.
- An async test or fixture is not handled as expected: Check
asyncio_mode, installed pytest-asyncio version, and whether the project uses another async plugin. Choose auto or strict based on plugin ownership rather than treating either as a speed switch. - Configuration appears to have no effect: Confirm the setting is in the pytest configuration file actually used for the run, and check for command-line mode overrides such as
--asyncio-mode. - Parameterized cases still take serial time: That is expected; pytest-asyncio documents them as running sequentially. Async work inside one test is not cross-test parallel scheduling.
- An old custom-loop fixture emits a deprecation warning: Consult current multiple-loop guidance and migrate from overriding
event_loop_policyto the recommended factory hook.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server, not a pytest runner; it will not make Python tests execute faster. If your test workflow also needs website screenshots, one GET request can capture a URL. See the ScreenshotNeo service and API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.
- An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for AI agents and MCP clients. - The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Does pytest-asyncio guarantee faster tests with session scope?
No. The documentation establishes the scope behavior, not a speed gain. Whether it helps depends on the measured costs and isolation needs of your suite.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsDoes pytest-asyncio run async test cases in parallel?
No. Its documentation says parametrized async cases run sequentially; concurrency within a test is a separate matter.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

