Skip to content

Commit d797187

Browse files
authored
Merge branch 'main' into short_info_excgroup
2 parents 47996bd + fe60ceb commit d797187

21 files changed

+435
-116
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
path: dist
5555

5656
- name: Publish package to PyPI
57-
uses: pypa/gh-action-pypi-publish@v1.10.3
57+
uses: pypa/gh-action-pypi-publish@v1.12.2
5858
with:
5959
attestations: true
6060

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ jobs:
246246

247247
- name: Upload coverage to Codecov
248248
if: "matrix.use_coverage"
249-
uses: codecov/codecov-action@v4
249+
uses: codecov/codecov-action@v5
250250
with:
251251
fail_ci_if_error: false
252252
files: ./coverage.xml

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.6.9"
3+
rev: "v0.7.3"
44
hooks:
55
- id: ruff
66
args: ["--fix"]
@@ -12,7 +12,7 @@ repos:
1212
- id: end-of-file-fixer
1313
- id: check-yaml
1414
- repo: https://github.com/adamchainz/blacken-docs
15-
rev: 1.19.0
15+
rev: 1.19.1
1616
hooks:
1717
- id: blacken-docs
1818
additional_dependencies: [black==24.1.1]
@@ -28,7 +28,7 @@ repos:
2828
hooks:
2929
- id: python-use-type-annotations
3030
- repo: https://github.com/pre-commit/mirrors-mypy
31-
rev: v1.11.2
31+
rev: v1.13.0
3232
hooks:
3333
- id: mypy
3434
files: ^(src/|testing/|scripts/)
@@ -44,13 +44,13 @@ repos:
4444
# on <3.11
4545
- exceptiongroup>=1.0.0rc8
4646
- repo: https://github.com/tox-dev/pyproject-fmt
47-
rev: "2.3.1"
47+
rev: "v2.5.0"
4848
hooks:
4949
- id: pyproject-fmt
5050
# https://pyproject-fmt.readthedocs.io/en/latest/#calculating-max-supported-python-version
5151
additional_dependencies: ["tox>=4.9"]
5252
- repo: https://github.com/asottile/pyupgrade
53-
rev: v3.18.0
53+
rev: v3.19.0
5454
hooks:
5555
- id: pyupgrade
5656
stages: [manual]
@@ -61,7 +61,8 @@ repos:
6161
entry: pylint
6262
language: system
6363
types: [python]
64-
args: ["-rn", "-sn", "--fail-on=I"]
64+
args: ["-rn", "-sn", "--fail-on=I", "--enable-all-extentions"]
65+
require_serial: true
6566
stages: [manual]
6667
- id: rst
6768
name: rst

changelog/10839.deprecation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Requesting an asynchronous fixture without a `pytest_fixture_setup` hook that resolves it will now give a DeprecationWarning. This most commonly happens if a sync test requests an async fixture. This should have no effect on a majority of users with async tests or fixtures using async pytest plugins, but may affect non-standard hook setups or ``autouse=True``. For guidance on how to work around this warning see :ref:`sync-test-async-fixture`.
File renamed without changes.
File renamed without changes.

changelog/12535.doc.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`This
2+
example`<https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures>
3+
showed ``print`` statements that do not exactly reflect what the
4+
different branches actually do. The fix makes the example more precise.

changelog/12966.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify :ref:`filterwarnings` docs on filter precedence/order when using multiple :ref:`@pytest.mark.filterwarnings <pytest.mark.filterwarnings ref>` marks.

doc/en/deprecations.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,76 @@ Below is a complete list of all pytest features which are considered deprecated.
1515
:class:`~pytest.PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.
1616

1717

18+
.. _sync-test-async-fixture:
19+
20+
sync test depending on async fixture
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
.. deprecated:: 8.4
24+
25+
Pytest has for a long time given an error when encountering an asynchronous test function, prompting the user to install
26+
a plugin that can handle it. It has not given any errors if you have an asynchronous fixture that's depended on by a
27+
synchronous test. If the fixture was an async function you did get an "unawaited coroutine" warning, but for async yield fixtures you didn't even get that.
28+
This is a problem even if you do have a plugin installed for handling async tests, as they may require
29+
special decorators for async fixtures to be handled, and some may not robustly handle if a user accidentally requests an
30+
async fixture from their sync tests. Fixture values being cached can make this even more unintuitive, where everything will
31+
"work" if the fixture is first requested by an async test, and then requested by a synchronous test.
32+
33+
Unfortunately there is no 100% reliable method of identifying when a user has made a mistake, versus when they expect an
34+
unawaited object from their fixture that they will handle on their own. To suppress this warning
35+
when you in fact did intend to handle this you can wrap your async fixture in a synchronous fixture:
36+
37+
.. code-block:: python
38+
39+
import asyncio
40+
import pytest
41+
42+
43+
@pytest.fixture
44+
async def unawaited_fixture():
45+
return 1
46+
47+
48+
def test_foo(unawaited_fixture):
49+
assert 1 == asyncio.run(unawaited_fixture)
50+
51+
should be changed to
52+
53+
54+
.. code-block:: python
55+
56+
import asyncio
57+
import pytest
58+
59+
60+
@pytest.fixture
61+
def unawaited_fixture():
62+
async def inner_fixture():
63+
return 1
64+
65+
return inner_fixture()
66+
67+
68+
def test_foo(unawaited_fixture):
69+
assert 1 == asyncio.run(unawaited_fixture)
70+
71+
72+
You can also make use of `pytest_fixture_setup` to handle the coroutine/asyncgen before pytest sees it - this is the way current async pytest plugins handle it.
73+
74+
If a user has an async fixture with ``autouse=True`` in their ``conftest.py``, or in a file
75+
containing both synchronous tests and the fixture, they will receive this warning.
76+
Unless you're using a plugin that specifically handles async fixtures
77+
with synchronous tests, we strongly recommend against this practice.
78+
It can lead to unpredictable behavior (with larger scopes, it may appear to "work" if an async
79+
test is the first to request the fixture, due to value caching) and will generate
80+
unawaited-coroutine runtime warnings (but only for non-yield fixtures).
81+
Additionally, it creates ambiguity for other developers about whether the fixture is intended to perform
82+
setup for synchronous tests.
83+
84+
The `anyio pytest plugin <https://anyio.readthedocs.io/en/stable/testing.html>`_ supports
85+
synchronous tests with async fixtures, though certain limitations apply.
86+
87+
1888
.. _import-or-skip-import-error:
1989

2090
``pytest.importorskip`` default behavior regarding :class:`ImportError`

doc/en/example/simple.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,9 @@ here is a little example implemented via a local plugin:
904904
# "function" scope
905905
report = request.node.stash[phase_report_key]
906906
if report["setup"].failed:
907-
print("setting up a test failed or skipped", request.node.nodeid)
907+
print("setting up a test failed", request.node.nodeid)
908+
elif report["setup"].skipped:
909+
print("setting up a test skipped", request.node.nodeid)
908910
elif ("call" not in report) or report["call"].failed:
909911
print("executing test failed or skipped", request.node.nodeid)
910912

0 commit comments

Comments
 (0)