CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

Option to have only exception str, but no traceback #247

Closed ocervell closed 3 years ago

ocervell commented 3 years ago

Seems that adding -e also suppress the exception name and cause. It would be great to keep them while supressing the traceback

Example with Arpeggio library:

Failure in tests.unit.test_promql.TestPromQLConversion.test_conversion (expr='sum by(pod)(rate(metric_test_app[2m] * 60)')
  File "/Users/ocervello/Workspace/dev/cloudops-migrator/tests/unit/test_promql.py", line 39, in test_conversion
    convert_promql_to_mql(expr)

... 1000 lines of traceback

    result = self._parse(parser)
  File "/Users/ocervello/.virtualenvs/cloudops-migrator/lib/python3.8/site-packages/arpeggio/__init__.py", line 370, in _parse
    result = e.parse(parser)
  File "/Users/ocervello/.virtualenvs/cloudops-migrator/lib/python3.8/site-packages/arpeggio/__init__.py", line 789, in parse
    result = self._parse(parser)
  File "/Users/ocervello/.virtualenvs/cloudops-migrator/lib/python3.8/site-packages/arpeggio/__init__.py", line 898, in _parse
    parser._nm_raise(self, c_pos, parser)
  File "/Users/ocervello/.virtualenvs/cloudops-migrator/lib/python3.8/site-packages/arpeggio/__init__.py", line 1718, in _nm_raise
    raise self.nm
arpeggio.NoMatch: Expected '[' or 'offset' or 'by' or '*' or '/' or '+' or '-' or 'or' or '>=' or '<=' or '>' or '<' or '==' or ')' at position (1, 43) => '[2m] * 60)*'.

Running with -e disables everything, but keeping just the last line would be super helpful (the traceback is pretty useless):

arpeggio.NoMatch: Expected '[' or 'offset' or 'by' or '*' or '/' or '+' or '-' or 'or' or '>=' or '<=' or '>' or '<' or '==' or ')' at position (1, 43) => '[2m] * 60)*'.
CleanCut commented 3 years ago

I wouldn't be opposed to such a feature. If you would like to give it a shot and make a pull request, I would be happy to review it.

You would probably only need to change config.py and result.py and add tests to test/test_config.py and test/test_result.py

Just searching for occurrences of no_tracebacks and doing the same thing with a new option in config.py should be enough to get a new option plumbed in, and then you would need to customize the output logic in result.py.

CleanCut commented 3 years ago

Closing due to lack of activity. I'd be happy to review a PR if someone wanted to give this a try, or reopen this issue if there is more to discuss. Otherwise, I'll consider the popular demand for this feature too low to bother with.