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

Failures in nested functions beyond one level raise AssertionError. #44

Open
joshuadavidthomas opened this issue Oct 31, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@joshuadavidthomas
Copy link
Collaborator

Failures in nested functions beyond one level raise AssertionError.

Basic reproduction:

def test_nested_failures():
    def inner():
        assert False
    inner()


def test_doubly_nested_failures():
    def inner():
        def inner_inner():
            assert False
        inner_inner()
    inner()


def test_triply_nested_failures():
    def inner():
        def inner_inner():
            def inner_inner_inner():
                assert False
            inner_inner_inner()
        inner_inner()
    inner()

The first function test_nested_failures fails as expected and prints the failure to the console, the other two raise an AssertionError and the test run quits.

@joshuadavidthomas
Copy link
Collaborator Author

Traceback

Traceback (most recent call last):
  File "/home/josh/.pyenv/versions/pytest-rich-3.10.6/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/_pytest/config/__init__.py", line 190, in console_main
    code = main()
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/_pytest/config/__init__.py", line 167, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/_pytest/main.py", line 317, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/_pytest/main.py", line 305, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/josh/projects/pytest-rich/src/pytest_rich/terminal.py", line 213, in pytest_sessionfinish
    self.console.print(tb)
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/rich/console.py", line 1694, in print
    extend(render(renderable, render_options))
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/rich/console.py", line 1326, in render
    for render_output in iter_render:
  File "/home/josh/projects/pytest-rich/src/pytest_rich/traceback.py", line 84, in __rich_console__
    self._render_chain(self.chain, options),
  File "/home/josh/.pyenv/versions/3.10.6/envs/pytest-rich-3.10.6/lib/python3.10/site-packages/rich/console.py", line 510, in _replace
    return Group(*renderables, fit=fit)
  File "/home/josh/projects/pytest-rich/src/pytest_rich/traceback.py", line 211, in _render_chain
    assert entry.reprfuncargs is not None

@joshuadavidthomas joshuadavidthomas added the bug Something isn't working label Oct 31, 2022
@joshuadavidthomas joshuadavidthomas changed the title Failures in nested functions beyond one level raise AssertionError. Failures in nested functions beyond one level raise AssertionError. Oct 31, 2022
@joshuadavidthomas
Copy link
Collaborator Author

joshuadavidthomas commented Oct 31, 2022

Expected outcome

Handle the nested failures similar to the builtin pytest terminal reporter:

_______________________________________________ test_nested_failure ________________________________________________

    def test_nested_failure():
        def inner():
            assert False
>       inner()

tests/example/test_basic.py:53:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def inner():
>       assert False
E       assert False

tests/example/test_basic.py:51: AssertionError
___________________________________________ test_doubly_nested_failures ____________________________________________

    def test_doubly_nested_failures():
        def inner():
            def inner_inner():
                assert False
            inner_inner()
>       inner()

tests/example/test_basic.py:63:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/example/test_basic.py:61: in inner
    inner_inner()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def inner_inner():
>       assert False
E       assert False

tests/example/test_basic.py:59: AssertionError
___________________________________________ test_triply_nested_failures ____________________________________________

    def test_triply_nested_failures():
        def inner():
            def inner_inner():
                def inner_inner_inner():
                    assert False
                inner_inner_inner()
            inner_inner()
>       inner()

tests/example/test_basic.py:76:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/example/test_basic.py:74: in inner
    inner_inner()
tests/example/test_basic.py:72: in inner_inner
    inner_inner_inner()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def inner_inner_inner():
>       assert False
E       assert False

@joshuadavidthomas
Copy link
Collaborator Author

Problem lines:

assert entry.reprfuncargs is not None
args = get_args(entry.reprfuncargs)
if args:
yield args

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant