facebook/TestSlide

Remove all "internal" stack trace lines

Closed this issue · 0 comments

Currently TestSlide test runner takes out all lines that are part of its own codebase, unless --show-testslide-stack-trace is given. It still lets out all third party libraries though:

$ python -m testslide.cli repro.py 
repro.Cause
  test_smoke: RuntimeError: Third

Failures:

  1) repro.Cause: test_smoke
    1) RuntimeError: Third
      File "/home/fornellas/.pyenv/versions/3.8.4/lib/python3.8/contextlib.py", line 120, in __exit__
        next(self.gen)
      File "/home/fornellas/.pyenv/versions/3.8.4/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
        yield
      File "/home/fornellas/.pyenv/versions/3.8.4/lib/python3.8/unittest/case.py", line 676, in run
        self._callTestMethod(testMethod)
      File "/home/fornellas/.pyenv/versions/3.8.4/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
        method()
      File "repro.py", line 12, in test_smoke
        raise RuntimeError("fail") from cause

Finished 1 example(s) in 0.6s 
  Failed: 1

If we compare this with unittest, it trims all lines, but the ones related to the test:

$ python -m unittest repro
E
======================================================================
ERROR: test_smoke (repro.Cause)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fornellas/src/TestSlide/repro.py", line 8, in test_smoke
    raise RuntimeError("fail")
RuntimeError: fail

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

Let's improve TestSlide to do the same.

The code at print_failed_example is the one that needs change. Things to consider taking out:

  • All Python internal libraries.
  • typeguard.

This has to be done intelligently though, so we do not exclude lines from stack trace, which uses these libraries, but originated from code being tested: we must only exclude if the origin of the call is TestSlide's codebase.