Skip to content
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

fix tests for strict exception groups #42

Merged
merged 13 commits into from
Apr 7, 2024

Conversation

VincentVanlaer
Copy link
Member

@VincentVanlaer VincentVanlaer commented Apr 2, 2024

  • fix tests to work with strict and non-strict exception groups
  • add python 3.12 to build, drop python 3.7 (end of life)
  • upgrade dev dependencies where needed for newer python versions

Required to do testing on python 3.11. Since anyio 4.0 always wraps
single exceptions with exception groups, we need to handle those in
certain pytest.raises calls. Luckily, trio has some helpers for this
that work irrespectively of whether the async loop is trio or not.
Anyio 4.0 has dropped python 3.7 as it is EOL.
.github/workflows/ci.yml Outdated Show resolved Hide resolved
This way tests can still be run with older versions of trio and anyio
Copy link

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment about how you updated the test dependencies lock file.

requirements_test.txt Show resolved Hide resolved
Comment on lines 9 to +11
from purerpc.test_utils import run_purerpc_service_in_process, run_grpc_service_in_process, \
async_iterable_to_list, random_payload, grpc_client_parallelize, purerpc_channel, purerpc_client_parallelize, grpc_channel
from .exceptiongroups import unwrap_exceptiongroups_single
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should unwrap_exceptiongroups_single go in test_utils? Like test_utils.async_iterable_to_list...

Though I'm not sure if test_utils is a public API cause unwrapping exceptiongroups is none of purerpc's business and maybe shouldn't go in public API -- but neither should turning an async iterable into a list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the reason I put it in a different location is because I didn't want to potentially expose it to users.

tests/test_errors.py Outdated Show resolved Hide resolved
requirements_test.txt Outdated Show resolved Hide resolved
@belm0 belm0 force-pushed the test-dependencies branch from bd2eb99 to fc76246 Compare April 7, 2024 22:14
@belm0 belm0 force-pushed the test-dependencies branch from fc76246 to 543b4bd Compare April 7, 2024 22:15
requirements_test.txt Outdated Show resolved Hide resolved
@belm0 belm0 force-pushed the test-dependencies branch 8 times, most recently from 686006e to af7e581 Compare April 7, 2024 23:18
@belm0 belm0 force-pushed the test-dependencies branch from af7e581 to 41aca19 Compare April 7, 2024 23:21
@belm0 belm0 force-pushed the test-dependencies branch from 41aca19 to 49b1304 Compare April 7, 2024 23:23
@belm0 belm0 changed the title Update test dependencies lock file fix tests for strict exception groups Apr 7, 2024
@belm0 belm0 merged commit eeecd24 into python-trio:master Apr 7, 2024
6 checks passed
@belm0
Copy link
Member

belm0 commented Apr 7, 2024

@VincentVanlaer I explained it in a thread of another project, but merely patching tests to handle strict exception groups doesn't provide any assurance that the runtime code supports strict exceptions. For example, where the API was previously raising a bare exception, it might now raise an ExceptionGroup (the API should probably never raise ExceptionGroup, since internal use of nurseries/concurrency is an implementation detail). Likewise, internally to the runtime, if there are any except statements catching bare exceptions, they need to be ported to excptiongroup catches.

Comment on lines +204 to 206
with pytest.raises(anyio.ClosedResourceError), unwrap_exceptiongroups_single():
async with purerpc.insecure_channel("localhost", port) as channel:
stub = echo_grpc.EchoStub(channel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially here. Now the purerpc API itself may raise ExceptionGroup. I don't think this implementation detail should be exposed, and the API should continue to raise ClosedResourceError.

I explained it in a thread of another project, but merely patching tests to handle strict exception groups doesn't provide any assurance that the runtime code supports strict exceptions. For example, where the API was previously raising a bare exception, it might now raise an ExceptionGroup (the API should probably never raise ExceptionGroup, since internal use of nurseries/concurrency is an implementation detail). Likewise, internally to the runtime, if there are any except statements catching bare exceptions, they need to be ported to excptiongroup catches.

@VincentVanlaer VincentVanlaer deleted the test-dependencies branch April 8, 2024 09:19
@VincentVanlaer
Copy link
Member Author

My main goal wasn't to fully assure the exception groups are as expected, but to have the dependencies be up to date to support python 3.11 (grpc is problematic, as it seems you have noticed) for runnign tests locally. I should have explained that in more detail, my bad! I agree with your assessment about exception groups though. Thanks for making the final changes!

@belm0
Copy link
Member

belm0 commented Apr 8, 2024

@VincentVanlaer what version of Trio is used in your project? I'm thinking of doing a purerpc release with the restriction anyio < 4.0 (and hence trio < 0.22), given that the package isn't ready for strict exception groups.

@VincentVanlaer
Copy link
Member Author

I'm currently using the latest trio release, and haven't encountered any problems. I'll make an issue to discuss this further this evening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants