returns.assert_trace doesn't work with @safe-wrapped functions
See original GitHub issueFirst of all, thank you! I really appreciate your work and your help on the Telegram group 😃
Bug report
What’s wrong
returns.assert_trace
fails to “intercept” containers created from @safe
decorators.
# works
def func_1(n) -> Result[int, Exception]:
if n == 0:
return Failure(Exception())
return Success(n + 1)
# doesn't work
@safe
def func_1(n) -> int:
if n == 0:
raise Exception()
return n + 1
def test_func_1(returns: ReturnsAsserts):
with returns.assert_trace(Success, func_1):
flow(1, func_1)
The test with the wrapped function returns
FAILED returns_test.py::test_func_1 - Failed: No container Success was created
I tried doing this, but no difference:
def test_func_1(returns: ReturnsAsserts):
with returns.assert_trace(Success, safe(func_1)):
flow(1, safe(func_1))
How is that should be
The above test should pass
System information
python
version: 3.8.0returns
version: 0.15.0pytest
version (if any): 6.2.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Result — returns 0.19.0 documentation - Docs
Decorator to convert exception-throwing function to Result container. It's very similar with returns.result.safe() , the difference is when an exception is ...
Read more >Add Error.Trace*(), and make Wrap/WithMessage never nest.
The solution is to not wrap an error, but to add trace information to the same error object. Ultimately it is error itself...
Read more >How can I elide a function wrapper from the traceback in ...
The simple answer is that you shouldn't do that. Hiding things from the traceback is dangerous. You may think you don't want to...
Read more >inspect — Inspect live objects — Python 3.11.1 documentation
Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback,...
Read more >Assert and Constexpr in C++11 - Eric Niebler
... in C++11 what's the best way to put debug checks in constexpr functions? Since assert is not constexpr , the obvious doesn't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks! Really appreciate your quick reply and help.
Here it is, I know it can be controversial but hopefully you’re not against it 🙃 https://github.com/ftruzzi/libgen_uploader
I am really excited to see your lib! 👍