pytest-dev / pytest-dev/pytest-asyncio
false-positive warning about missing asyncio_default_fixture_loop_scope with nested pytest config files
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 207
- Avg merge
- 5h 35m
- Merged PRs (30d)
- 9
Description
My situation
I have an application which itself uses pytest. I therefore have two config files for pytest:
- An "outer" config file (I use
pyproject.toml) which controls tests of the application itself. - An "inner"
pytest.iniconfig file, located in a project subdir that's included in the published package, which controls howpytestruns when executed by the running application.
In pyproject.toml, I've included:
[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"
In that inner pytest.ini, I don't have a setting for asyncio_default_fixture_loop_scope - it should not be needed, since the running application doesn't use the pytest-asyncio plugin.
What I expect
When I run pytest to test the application (i.e., start it from the project root-dir and verify that it reports that it's using pyproject.toml as the config file), I expect no warnings about unset asyncio_default_fixture_loop_scope.
What actually happens
I still get the warning. I see this in console output:
My console output
% pytest
Test session starts (platform: darwin, Python 3.11.10, pytest 8.2.2, pytest-sugar 1.0.0)
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /Users/jclerman/git/backend-integration-tester
configfile: pyproject.toml
plugins: ddtrace-2.14.4, cov-5.0.0, sugar-1.0.0, icdiff-0.9, benchmark-4.0.0, anyio-4.6.2.post1, asyncio-0.25.1
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=function
... # omitting test-results here
============================================================================================================= warnings summary =============================================================================================================
tests/rest_api/test_routes.py::test_start_test_run[request_payload0-2-2-1-0-1]
tests/rest_api/test_routes.py::test_start_test_run[request_payload1-2-0-0-0-0]
/Users/jclerman/Library/Caches/pypoetry/virtualenvs/backend-integration-tester-V08Hc2cc-py3.11/lib/python3.11/site-packages/pytest_asyncio/plugin.py:207: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"
warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
Workaround
I have verified that adding the option to the inner pytest.ini makes the warning disappear.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the warning with an outer pyproject.toml and an inner pytest.ini, confirming that pytest reports the outer file as its configfile. Start at pytest_asyncio/plugin.py:207 and trace how asyncio_default_fixture_loop_scope is read; done means the nested configuration no longer causes a warning when the outer setting is present, while the existing workaround remains unnecessary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100