JetBrains / teamcity-messages

Python Unit Test Reporting to TeamCity
https://pypi.python.org/pypi/teamcity-messages
Apache License 2.0
137 stars 81 forks source link

Format twisted Failure objects #183

Closed jackrobison closed 5 years ago

jackrobison commented 6 years ago

This fixes a "too many values to unpack" error when the format function is given a twisted Failure object when running tests with trial in pycharm.

eukreign commented 6 years ago

This is great! I'm using twisted trial with PyCharm and this fixed my issue.

shalupov commented 6 years ago

Thanks! Do you know how to reproduce it in tests? Which version of Twisted involved?

jackrobison commented 6 years ago

@shalupov

When running the following with trial as the test runner in PyCharm:

from twisted.trial import unittest
from twisted.python.failure import Failure

class TestPyCharmFailure(unittest.TestCase):
    def test_raise_failure(self):
        raise Failure(Exception("test"))

You get an error formatting the uncaught exception:

[Failure instance: Traceback (failure with no frames): <type 'exceptions.Exception'>: test
]
Error
*FAILED TO GET TRACEBACK*: Traceback (most recent call last):
  File "~/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/181.5087.37/helpers/pycharm/teamcity/common.py", line 131, in convert_error_to_string
    exctype, value, tb = err
ValueError: need more than 1 value to unpack

With the change the exception is formatted correctly:

Error
Exception: test

I'm using twisted 16.6.0, but I don't think that should effect it.

eukreign commented 6 years ago

One issue I've found so far with this though is if there is an unrelated ImportError (twisted is installed) it will fail. For example, I'm experiencing this:

Error
*FAILED TO GET TRACEBACK*: Traceback (most recent call last):
  File "/home/lex/bin/pycharm-2018.1.3/helpers/pycharm/teamcity/common.py", line 137, in convert_error_to_string
    trace = traceback.format_exception(exctype, value, tb)
  File "/usr/lib/python3.5/traceback.py", line 117, in format_exception
    type(value), value, tb, limit=limit).format(chain=chain))
  File "/usr/lib/python3.5/traceback.py", line 442, in __init__
    if (exc_value and exc_value.__cause__ is not None
AttributeError: 'tuple' object has no attribute '__cause__'

===============================================================================
[ERROR]
Traceback (most recent call last):
Failure: builtins.tuple: (<class 'ImportError'>, ImportError("No module named 'pylru'",), <traceback object at 0x7f2219f20448>)

^ you can see that err tuple didn't get expanded into exctype, value, tb

jackrobison commented 6 years ago

Bump

throwable-one commented 6 years ago

Hello @jackrobison Thank you for this fix.

Do you think it is possible to move twisted-specific logic somewhere to twisted/plugins/teamcity_plugin.py to make common.py framework-agnostic?

We also have tests for this package (yes, tests for test runners:)). They are pytest-based, so it will be really good to have test for this fix.

shalupov commented 5 years ago

Rewritten to be independent of twisted, merged to master