Skip to content

Bug: Traceback cleanup fails on Exception/pytest.fail in Item.runtest #7692

Open

Description

@0az
  • a detailed description of the bug or suggestion
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible
    • Not strictly minimal, but I'll see if I can minimize it sometime this week.

I have a small plugin that dynamically generates tests based on some custom boilerplate. These tests have the following form [0]:

# In Item subclass
def runtest(self):
	assert self.function(*self.args, **self.kwargs)

One such test happens to fail, with the following traceback: [1]. pytest.fail also results in similar output. Clearly, something went wrong – even frames with __tracebackhide__ are getting shown.

pip list
Package             Version                 Location
------------------- ----------------------- ------------------------------------------------------------
appdirs             1.4.4
attrs               20.1.0
black               19.10b1.dev141+g820f387 <snip>/.venv/src/black/src
cfgv                3.2.0
click               7.1.2
distlib             0.3.1
docutils            0.16
filelock            3.0.12
flake8              3.8.3
flake8-bugbear      20.1.4
flake8-plugin-utils 1.3.1
flake8-pytest-style 1.2.3
hypothesis          5.28.0
identify            1.4.28
iniconfig           1.0.1
isort               5.4.2
mccabe              0.6.1
more-itertools      8.4.0
mypy                0.782
mypy-extensions     0.4.3
nodeenv             1.5.0
packaging           20.4
pathspec            0.8.0
pip                 20.1.1
pluggy              0.13.1
ppcg                0.0.0                   <snip>/src
pre-commit          2.7.1
py                  1.9.0
pycodestyle         2.6.0
pyflakes            2.2.0
Pygments            2.6.1
pyparsing           2.4.7
pyperclip           1.8.0
pyroma              2.6
pytest              6.0.1
PyYAML              5.3.1
regex               2020.7.14
setuptools          47.1.0
six                 1.15.0
sortedcontainers    2.2.2
toml                0.10.1
typed-ast           1.4.1
typing-extensions   3.7.4.3
virtualenv          20.0.31
vulture             1.5

Activity

  1. asottile commented on Aug 27, 2020

    @asottile
    Member

    it's easily reproducible with the nonpython example in the docs, but by removing the custom exception repr / failure messaging

  2. asottile commented on Aug 27, 2020

    @asottile
    Member

    this improves the output:

    diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py
    index 26fab67fe..fe359cbc4 100644
    --- a/src/_pytest/nodes.py
    +++ b/src/_pytest/nodes.py
    @@ -410,7 +410,7 @@ class Node(metaclass=NodeMeta):
                 abspath=abspath,
                 showlocals=self.config.getoption("showlocals", False),
                 style=style,
    -            tbfilter=False,  # pruned already, or in --fulltrace mode.
    +            tbfilter=not self.config.getoption('fulltrace', False),
                 truncate_locals=truncate_locals,
             )
     

    but I suspect that the expectation is if you implement an Item you should also implement repr_failure

  3. asottile commented on Aug 27, 2020

    @asottile
    Member

    (note that while it improves the output, it still contains many frames of pytest plugin calls)

  4. added
    topic: reportingrelated to terminal output and user-facing messages and errors
    type: bugproblem that needs to be addressed
    on Aug 28, 2020
  5. gdhameeja commented on Aug 31, 2020

    @gdhameeja
    Contributor

    I'd like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions