Skip to content

Duplicated exception on console #35

@bigbirdcode

Description

@bigbirdcode

Hi, ensure looks promising!
However, I have tried the simplest failure of ensure(1).equals(2) and my script showed two exceptions:

Traceback (most recent call last):
  File "c:\Users\Peter\Documents\work\ensure_try\.venv\Lib\site-packages\ensure\main.py", line 71, in _run
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "c:\python312\Lib\unittest\case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "c:\python312\Lib\unittest\case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 1 != 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Peter\Documents\work\ensure_try\hello.py", line 9, in <module>
    main()
  File "c:\Users\Peter\Documents\work\ensure_try\hello.py", line 5, in main
    ensure(1).equals(2)
  File "c:\Users\Peter\Documents\work\ensure_try\.venv\Lib\site-packages\ensure\main.py", line 205, in equals
    self._run(unittest_case.assertEqual, (self._subject, other))
  File "c:\Users\Peter\Documents\work\ensure_try\.venv\Lib\site-packages\ensure\main.py", line 74, in _run
    raise new_err
ensure.main.EnsureError: 1 != 2

I would like to see only the second, as the first is only internal detail.

I think in main.py line 74 you would need raise new_err from None instead of raise new_err.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions