-
-
Notifications
You must be signed in to change notification settings - Fork 375
Deprecate testing.RaisesGroup and testing.Matcher
#3337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Deprecate testing.RaisesGroup and testing.Matcher
#3337
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3337 +/- ##
===============================================
Coverage 100.00000% 100.00000%
===============================================
Files 128 128
Lines 19407 19407
Branches 1318 1318
===============================================
Hits 19407 19407
🚀 New features to boost your workflow:
|
|
Makes sense. However even if I deprecate it on _deprecate.deprecate_attributes(
__name__,
{
"RaisesGroup": _deprecate.DeprecatedAttribute(
"RaisesGroup",
version="0.32.0",
issue=3326,
instead="See https://docs.pytest.org/en/stable/reference/reference.html#pytest.RaisesGroup",
)
},
)On |
|
I think the deprecation should go in I'm probably misunderstanding what you're saying cause it sounds like you tried that... |
|
Note that this is how the usage looks like (it's a bit complicated because you need the actual underlying object, but under a different name) deprecate_attributes(__name__, {
"RaisesGroup": DeprecatedAttribute(_RaisesGroup, "0.32.0", ...)
}) |
A5rocks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just putting in an actual review because GitHub keeps wanting me to see this. Previous comments still apply!
|
note that |
with RaisesGroup(
Matcher(_core.BrokenResourceError, match="^Parking lot broken by"),
):
async with _core.open_nursery() as nursery:
nursery.start_soon(bad_parker, lot, cs)
await wait_all_tasks_blocked()
nursery.start_soon(lot.park)
await wait_all_tasks_blocked()
cs.cancel()How should I supposed to write this via pytest alternatives, specifically
[tool.pytest.ini_options]
filterwarnings = [
# ...
'ignore::trio.TrioDeprecationWarning:trio._tests.test_testing_raisesgroup'
]From my point of view, files that should suppress deprecations are:
Anything else ? |
|
@AbduazizZiyodov I might be misunderstanding things but:
|
|
|
@AbduazizZiyodov just bumping since it would be nice to get this by the next release. (which will be... I don't know yet, maybe New Year's would be a nice time?) |
|
@A5rocks Yep, we can do that (till new year's). |
Tried with minimal reproducer whether it works:
All tests were passing locally:
Suggestion: rename the title of issue & PR (I'll do myself) edit: there was one merge conflict, it is fixed -- needs to be checked. Thanks. |
RaisesGrouptesting.RaisesGroup and testing.Matcher
|
I guess ... CI is failing because of this, because attribute access emits deprecation warning. Should we suppress warning on this test case or just remove the portion of the code ? |
Why does that trigger a deprecation? That seems to only do stuff for trio.socket, based on a quick read. |
My bad, wrong link. Correct one: trio/src/trio/_tests/test_exports.py Line 336 in b178251
|
|
IMO check the qualname (or name) of the class then. |
Something like this |
|
Yeah plus a check on module name I guess. |
…ses (RaisesGroup, Matcher)
|
Its done. But ... |
A5rocks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just nitpicks. Thanks for the PR!
| # to be reimplemented in pytest). | ||
| # Not 100% that's the case, and it works locally, so whatever /shrug | ||
| if module_name == "trio.testing" and class_name in ("RaisesGroup", "Matcher"): | ||
| if module_name == "trio.testing" and class_name in ("_RaisesGroup", "_Matcher"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add underscore prefix to match the convention used in exports (testing/__init__.py). This fixed test cases, except "type tests".
I tried to fix these also, you might check the diff (produced locally):
diff --git a/src/trio/_tests/test_testing_raisesgroup.py b/src/trio/_tests/test_testing_raisesgroup.py
index 9cc92993..4b6f787e 100644
--- a/src/trio/_tests/test_testing_raisesgroup.py
+++ b/src/trio/_tests/test_testing_raisesgroup.py
@@ -7,7 +7,7 @@ from types import TracebackType
import pytest
import trio
-from trio.testing import Matcher, RaisesGroup
+from trio.testing import _Matcher as Matcher, _RaisesGroup as RaisesGroup
from trio.testing._raises_group import repr_callable
if sys.version_info < (3, 11):
@@ -1107,7 +1107,7 @@ def test__ExceptionInfo(monkeypatch: pytest.MonkeyPatch) -> None:
"ExceptionInfo",
trio.testing._raises_group._ExceptionInfo,
)
- with trio.testing.RaisesGroup(ValueError) as excinfo:
+ with RaisesGroup(ValueError) as excinfo:
raise ExceptionGroup("", (ValueError("hello"),))
assert excinfo.type is ExceptionGroup
assert excinfo.value.exceptions[0].args == ("hello",)
diff --git a/src/trio/_tests/test_util.py b/src/trio/_tests/test_util.py
index 69310d64..c8beefa1 100644
--- a/src/trio/_tests/test_util.py
+++ b/src/trio/_tests/test_util.py
@@ -9,7 +9,7 @@ if TYPE_CHECKING:
import pytest
import trio
-from trio.testing import Matcher, RaisesGroup
+from trio.testing import _Matcher as Matcher, _RaisesGroup as RaisesGroup
from .. import _core
from .._core._tests.tutil import (
diff --git a/src/trio/_tests/type_tests/raisesgroup.py b/src/trio/_tests/type_tests/raisesgroup.py
index 012c42b4..86c758ec 100644
--- a/src/trio/_tests/type_tests/raisesgroup.py
+++ b/src/trio/_tests/type_tests/raisesgroup.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import sys
from collections.abc import Callable
-from trio.testing import Matcher, RaisesGroup
+from trio.testing import _Matcher as Matcher, _RaisesGroup as RaisesGroup
from typing_extensions import assert_type
if sys.version_info < (3, 11):Which are basically import errors, but again pyright still "screaming":
❯ tox -m check
.pkg: _optional_hooks> python /home/abduaziz/Projects/OSS/trio/.venv/lib/python3.13/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_wheel> python /home/abduaziz/Projects/OSS/trio/.venv/lib/python3.13/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_wheel> python /home/abduaziz/Projects/OSS/trio/.venv/lib/python3.13/site-packages/pyproject_api/_backend.py True setuptools.build_meta
gen_exports: install_package> python -I -m pip install --force-reinstall --no-deps /home/abduaziz/Projects/OSS/trio/.tox/.tmp/package/33/trio-0.32.0+dev-py3-none-any.whl
gen_exports: commands[0]> python ./src/trio/_tools/gen_exports.py --test
Scanning: /home/abduaziz/Projects/OSS/trio/src/trio/_core/_run.py
Scanning: /home/abduaziz/Projects/OSS/trio/src/trio/_core/_instrumentation.py
Scanning: /home/abduaziz/Projects/OSS/trio/src/trio/_core/_io_windows.py
Scanning: /home/abduaziz/Projects/OSS/trio/src/trio/_core/_io_epoll.py
Scanning: /home/abduaziz/Projects/OSS/trio/src/trio/_core/_io_kqueue.py
Generated sources are up to date.
gen_exports: OK ✔ in 2.69 seconds
pip_compile: install_package> python -I -m pip install --force-reinstall --no-deps /home/abduaziz/Projects/OSS/trio/.tox/.tmp/package/34/trio-0.32.0+dev-py3-none-any.whl
pip_compile: commands[0]> pre-commit run pip-compile --all-files
uv pip-compile test-requirements.in......................................Passed
uv pip-compile docs-requirements.in......................................Passed
pip_compile: OK ✔ in 1 second
typing: install_package> python -I -m pip install --force-reinstall --no-deps /home/abduaziz/Projects/OSS/trio/.tox/.tmp/package/35/trio-0.32.0+dev-py3-none-any.whl
typing: commands[0]> mypy --platform linux
Success: no issues found in 148 source files
typing: commands[1]> mypy --platform darwin
Success: no issues found in 148 source files
typing: commands[2]> mypy --platform win32
Success: no issues found in 148 source files
typing: commands[3]> pyright src/trio/_tests/type_tests
/home/abduaziz/Projects/OSS/trio/src/trio/_tests/type_tests/raisesgroup.py
/home/abduaziz/Projects/OSS/trio/src/trio/_tests/type_tests/raisesgroup.py:6:26 - error: "_Matcher" is private and used outside of the module in which it is declared (reportPrivateUsage)
/home/abduaziz/Projects/OSS/trio/src/trio/_tests/type_tests/raisesgroup.py:6:47 - error: "_RaisesGroup" is private and used outside of the module in which it is declared (reportPrivateUsage)
2 errors, 0 warnings, 0 informations
typing: exit 1 (1.54 seconds) /home/abduaziz/Projects/OSS/trio> pyright src/trio/_tests/type_tests pid=34297
typing: FAIL ✖ in 36.66 seconds
type_completeness: install_package> python -I -m pip install --force-reinstall --no-deps /home/abduaziz/Projects/OSS/trio/.tox/.tmp/package/36/trio-0.32.0+dev-py3-none-any.whl
type_completeness: commands[0]> python src/trio/_tests/check_type_completeness.py
********************
Checking Linux...
Congratulations, you have resolved existing errors! Please remove them from /home/abduaziz/Projects/OSS/trio/src/trio/_tests/_check_type_completeness.json, either manually or with '--overwrite-file'.
['No docstring found for function "trio.testing._raises_group._ExceptionInfo.exconly"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.errisinstance"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.getrepr"', 'No docstring found for function "trio.testing._raises_group.RaisesGroup.expected_type"']
********************
Checking Windows...
********************
Checking Darwin...
Congratulations, you have resolved existing errors! Please remove them from /home/abduaziz/Projects/OSS/trio/src/trio/_tests/_check_type_completeness.json, either manually or with '--overwrite-file'.
['No docstring found for function "trio.testing._raises_group._ExceptionInfo.exconly"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.errisinstance"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.getrepr"', 'No docstring found for function "trio.testing._raises_group.RaisesGroup.expected_type"']
********************
Congratulations, you have resolved existing errors! Please remove them from /home/abduaziz/Projects/OSS/trio/src/trio/_tests/_check_type_completeness.json, either manually or with '--overwrite-file'.
['No docstring found for function "trio.testing._raises_group._ExceptionInfo.exconly"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.errisinstance"', 'No docstring found for function "trio.testing._raises_group._ExceptionInfo.getrepr"', 'No docstring found for function "trio.testing._raises_group.RaisesGroup.expected_type"']
type_completeness: exit 1 (5.14 seconds) /home/abduaziz/Projects/OSS/trio> python src/trio/_tests/check_type_completeness.py pid=34335
gen_exports: OK (2.69=setup[1.49]+cmd[1.20] seconds)
pip_compile: OK (1.00=setup[0.70]+cmd[0.29] seconds)
typing: FAIL code 1 (36.66=setup[0.70]+cmd[11.40,11.34,11.68,1.54] seconds)
type_completeness: FAIL code 1 (5.86=setup[0.71]+cmd[5.14] seconds)
evaluation failed :( (46.28 seconds)My concern is that am I in right direction ?



Closes #3326 by deprecating both
testing.RaisesGroupandtesting.Matcherwhere pytest alternative recommended from now on..Replaced existing test cases with pytest alternatives.