Comments (4)
I'm not a fan of this parameter, in large part because the end goal is to move RaisesGroup
into upstream pytest, and it's hard for me to make a strong case for adding it there. It also brings up a bunch of follow-up questions: why should RaisesGroup
have this functionality, but not pytest.raises
? Should it be possible to unset .must_reach_this_point
? Can one require setting it multiple times? Or what about multiple different .must_reach_this_point
s?
I could even see pytest newbies creating really broad with RaisesGroup
blocks, or even going as far as manually raising ExceptionGroup
s just to use the must-reach-this-point functionality.
I think making sure a specific line of code runs is a super common problem that comes up in tons of other situations, not just when we expect ExceptionGroup
s to be raised. So adding custom logic for this one specific case needs a strong reason imo - which I'm not sure this scenario when there are fairly painless ways of achieving it in other ways.
Another option for rewriting it would be to unroll the async with
statement:
my_cm = some_async_context_manager()
await my_cm.__aenter__()
...
with RaisesGroup(...):
await my_cm.__aexit__()
(which would make PT012 very happy), making it very explicit that you're only testing the exit. though ofc it is somewhat clunky.
Yet another option, keep your AssertRaises
- but make it a subclass of RaisesGroup
, delegating all the exception logic to it and only adding on your .must_reach_this_point()
. Something like
class AssertRaises(trio.testing.RaisesGroup):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.has_reached=False
def must_reach_this_point(self):
self.has_reached=True
def __exit__(self, *args):
assert self.has_reached
super().__exit__(*args)
from trio.
Fair enough, the subclass trick does seem like a better solution than upstreaming everything.
from trio.
Alternatively, I think it would be possible to just have another context manager (not a subclass) and use that! You could probably even then use a pytest fixture and allow it for non-exception group tests. To be specific, something like this (not sure if this works, just copying from the subclass above + edits):
class GetsTo():
def __init__(self):
self.has_reached=False
def must_reach_this_point(self):
self.has_reached=True
# some definition of __enter__, I think this is the right definition?:
def __enter__(self, *args):
return None
def __exit__(self, *args):
assert self.has_reached
from trio.
Hm, I considered that one as well but thought it wouldn't be able to perfectly replicate the behaviour with printing the stacktrace if the point wasn't reached. But thinking about it again now I don't see why it wouldn't work.
Just gotta make sure to place the GetsTo()
CM inside the RaisesGroup()
, and to always return False
(unless the assert fails) in __exit__
so as not to suppress the expected exception[group].
from trio.
Related Issues (20)
- Please switch to v1.0 and start using semantic version numbers HOT 17
- Could this lib I made be added to the Awesome Libraries page? HOT 4
- Using trio with httpx in a basic example works. In a basic locust script it fails with `NotImplementedError: unsupported platform` HOT 11
- Cancellation may not always immediately happen at checkpoints HOT 8
- Move `pytest-trio`'s hook for deterministic Hypothesis tests upstream into Trio
- v0.25.0 Broke support for Windows embedded Python HOT 1
- Remove (Deprecate??) TrioDeprecationWarning HOT 4
- > (my perspective is someone who uses Trio for concurrency uses and very much a networking noob!)
- open_nursery is unable to call move_on_after when it is active, but it can still work. HOT 2
- Remaining test issues with Python 3.13.0b1: not ki_protected, pathlib.Path.resolve siganture HOT 6
- Ctrl+C behavior problems at the new REPL HOT 7
- Would be to actually port aiomultiprocess to trio? HOT 1
- No support aiohttp? HOT 2
- Trio fails under gevent with NotImplementedError: unsupported platform HOT 11
- AttributeError: type object 'GreenSocket' has no attribute 'sendmsg' HOT 4
- Add `TypeVarTuple` to `Nursery.start` HOT 3
- unexpected StopAsyncIteration HOT 6
- Why can't you await __aenter__? (Understanding trio's contracts around async context managers) HOT 5
- Problems with `trio.Lock()` across multiple tasks HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trio.