question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

returns.assert_trace doesn't work with @safe-wrapped functions

See original GitHub issue

First 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.0
  • returns version: 0.15.0
  • pytest version (if any): 6.2.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
ftruzzicommented, Mar 27, 2021

Thanks! Really appreciate your quick reply and help.

I am really excited to see your lib! 👍

Here it is, I know it can be controversial but hopefully you’re not against it 🙃 https://github.com/ftruzzi/libgen_uploader

0reactions
sobolevncommented, Mar 26, 2021

I am really excited to see your lib! 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found