Skip to content

Use test body as traceback when empty #1493

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

Closed
max4t opened this issue Mar 30, 2016 · 1 comment
Closed

Use test body as traceback when empty #1493

max4t opened this issue Mar 30, 2016 · 1 comment

Comments

@max4t
Copy link

max4t commented Mar 30, 2016

Hi,
I've added a 'raises' marker for my tests and to handle these, i've created a runtest wrapper like this:

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
    #__tracebackhide__ = True
    if item.get_marker("raises"):
        with pytest.raises(item.get_marker("raises").kwargs['error']):
            outcome = (yield)
            outcome.get_result()
        outcome.force_result(None)
    else:
        yield

It works fine except for the traceback because if the test did not raise any exception, it's not in the trace anymore and the trace of the wrapper will be printed instead.
If i use the 'tracebackhide' variable to ignore the trace of the wrapper, the traceback is empty which raise an error like this:

.......
  File "./venv/lib/python3.4/site-packages/_pytest/_code/code.py", line 418, in getrepr
    return fmt.repr_excinfo(self)
  File "./venv/lib/python3.4/site-packages/_pytest/_code/code.py", line 598, in repr_excinfo
    reprtraceback = self.repr_traceback(excinfo)
  File "./venv/lib/python3.4/site-packages/_pytest/_code/code.py", line 585, in repr_traceback
    last = traceback[-1]
  File "./venv/lib/python3.4/site-packages/_pytest/_code/code.py", line 289, in __getitem__
    val = super(Traceback, self).__getitem__(key)
IndexError: list index out of range

Wouldn't it be useful to print the test body as traceback if it's empty? Instead of printing the pytest_runtest_call body (without tracebackhide) or raising an error (with tracebackhide).

It would be useful to mark cases of a parametrized test.

@max4t max4t changed the title [feature] Use test body as traceback when empty Use test body as traceback when empty Mar 30, 2016
@nicoddemus
Copy link
Member

Thanks, closing as duplicate of #905 (added your suggestion there as well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants