Hard to tell what went wrong when a text content object is broken #111

Closed
thomir opened this Issue Oct 16, 2014 · 4 comments

Comments

Projects
None yet
3 participants
Member

thomir commented Oct 16, 2014

I see lots of stack traces such as this one:

Traceback

Traceback (most recent call last):
  File "/usr/bin/autopilot3", line 9, in <module>
    load_entry_point('autopilot==1.5.0', 'console_scripts', 'autopilot3')()
  File "/usr/lib/python3/dist-packages/autopilot/run.py", line 729, in main
    test_app.run()
  File "/usr/lib/python3/dist-packages/autopilot/run.py", line 617, in run
    action()
  File "/usr/lib/python3/dist-packages/autopilot/run.py", line 681, in run_tests
    test_result = test_suite.run(result)
  File "/usr/lib/python3.4/unittest/suite.py", line 125, in run
    test(result)
  File "/usr/lib/python3.4/unittest/case.py", line 625, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3/dist-packages/testscenarios/testcase.py", line 62, in run
    test.run(result)
  File "/usr/lib/python3/dist-packages/testscenarios/testcase.py", line 65, in run
    return super(WithScenarios, self).run(result)
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 585, in run
    return self.__RunTest(self, self.exception_handlers).run(result)
  File "/usr/lib/python3/dist-packages/testtools/runtest.py", line 74, in run
    return self._run_one(actual_result)
  File "/usr/lib/python3/dist-packages/testtools/runtest.py", line 88, in _run_one
    return self._run_prepared_result(ExtendedToOriginalDecorator(result))
  File "/usr/lib/python3/dist-packages/testtools/runtest.py", line 107, in _run_prepared_result
    handler(self.case, self.result, e)
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 558, in _report_failure
    result.addFailure(self, details=self.getDetails())
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1149, in addFailure
    return self.decorated.addFailure(test, err)
  File "/usr/lib/python3/dist-packages/autopilot/testresult.py", line 78, in addFailure
    return super(type(self), self).addFailure(test, err, details)
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1546, in addFailure
    return self.decorated.addFailure(test, err, details=details)
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1322, in addError
    self._convert(test, err, details, 'fail')
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1350, in _convert
    test_tags=self.current_tags, timestamp=now)
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 408, in status
    super(CopyStreamResult, self).status(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 649, in status
    self.on_test(self._inprogress.pop(key))
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 742, in _gather_test
    self._handle_status[test_dict['status']](case)
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 761, in _fail
    message = _details_to_str(case._details, special="traceback")
  File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1752, in _details_to_str
    text = content.as_text().strip()
  File "/usr/lib/python3/dist-packages/testtools/content.py", line 94, in as_text
    return _u('').join(self.iter_text())
  File "/usr/lib/python3/dist-packages/testtools/content.py", line 118, in _iter_text
    yield decoder.decode(bytes)
  File "/usr/lib/python3.4/encodings/latin_1.py", line 26, in decode
    return codecs.latin_1_decode(input,self.errors)[0]
TypeError: 'NoneType' does not support the buffer interface

... where testtools attempts to convert a content object to a string, only to find that even though the content type of the content object is 'text', the content object returns something other than text.

This has been partially fixed in a separate PR that makes the text_content function more picky about what it accepts, but I think we should also catch the raised exception, and re-raise with the name of the content object being processed.

@thomir thomir self-assigned this Oct 16, 2014

Owner

jml commented Oct 21, 2014

So you're suggesting earlier, stricter type checking in text_content? Sounds good to me.

Member

thomir commented Oct 21, 2014

@jml I was suggesting that, but @rbtcollins didn't like the whack-a-mole approach here - i.e.- we keep finding these places, and keep having to patch testtools. AIUI, he's suggesting making testtools tracebacks print frame locals, which might at least give us the information we need. There's a long thread on the TIP ML you may have seen...

I'd still like to fix this sooner rather than later. I'm wondering if I can convince @rbtcollins to accept a specific fix as well.

Thoughts?

Owner

rbtcollins commented Nov 15, 2014

I won't push back against a tasteful specific fix. I just am not sure that there is one that won't actually be a net negative. Re-raising needs to be done carefully with 3.x because of chaining.

rbtcollins added a commit to rbtcollins/testtools that referenced this issue Mar 9, 2015

Overhaul exception reporting.
unittest2 recently added the ability to show local variables in
tracebacks as testing-cabal#111
requested for us. Reusing that requires some refactoring of our code,
in particular where we were reimplementing bits of the traceback
module. Now we can just hard-depend on traceback2 and linecache2 which
are brought in by unittest2 1.0.0.

Change-Id: Ieb3268029d26b48ed4fcd25ed644bd339f6aa3fb

rbtcollins added a commit to rbtcollins/testtools that referenced this issue Mar 9, 2015

Overhaul exception reporting.
unittest2 recently added the ability to show local variables in
tracebacks as testing-cabal#111
requested for us. Reusing that requires some refactoring of our code,
in particular where we were reimplementing bits of the traceback
module. Now we can just hard-depend on traceback2 and linecache2 which
are brought in by unittest2 1.0.0.

Change-Id: Ieb3268029d26b48ed4fcd25ed644bd339f6aa3fb

rbtcollins added a commit to rbtcollins/testtools that referenced this issue Mar 9, 2015

Overhaul exception reporting.
unittest2 recently added the ability to show local variables in
tracebacks as testing-cabal#111
requested for us. Reusing that requires some refactoring of our code,
in particular where we were reimplementing bits of the traceback
module. Now we can just hard-depend on traceback2 and linecache2 which
are brought in by unittest2 1.0.0.

Change-Id: Ieb3268029d26b48ed4fcd25ed644bd339f6aa3fb
Owner

rbtcollins commented Mar 10, 2015

Fixed IMO - run with --locals, should be pretty clear.

@rbtcollins rbtcollins closed this Mar 10, 2015

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