beeware / cricket

A GUI tool for running Python test suites.
BSD 3-Clause "New" or "Revised" License
213 stars 68 forks source link

Print statements in the code will cause an exception in cricket #21

Closed khoobks closed 11 years ago

khoobks commented 11 years ago

Print statements in the test or source code being tested will cause cricket to stop working and throw the following exception.

Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1473, in __call__
    return self.func(*args)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 534, in callit
    func(*args)
  File "/home/benk/workspace/swcc/VirtualEnv/local/lib/python2.7/site-packages/cricket/view.py", line 706, in on_testProgress
    if self.executor and self.executor.poll():
  File "/home/benk/workspace/swcc/VirtualEnv/local/lib/python2.7/site-packages/cricket/executor.py", line 133, in poll
    post = json.loads(self.buffer[1])
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

The Test being run is

from django.core.urlresolvers import reverse

from django.utils import unittest
from django.test.client import Client

class StaticPageTestCase(unittest.TestCase):

    def setUp(self):
        self.client = Client()

    def test_disclaimer_page(self):
        self.client.login(username='admin', password='password')
        """Disclaimer page can be rendered."""
        response = self.client.get(reverse('disclaimer'))
        self.assertEqual(response.status_code, 200)
        print 'fozzy'

The contents of the buffer on executor.py line 133 is

['{"path": "swcc.StaticPageTestCase.test_disclaimer_page", "start_time": 1375254062.688251}', 'fozzy', '{"status": "OK", "output": "", "end_time": 1375254063.314388, "description": "No description"}']

A possible (temporary) workaround is to modify line 133 of executor.py to read

post = json.loads(self.buffer[-1])
freakboy3742 commented 11 years ago

Confirmed. This is a regression, because capturing Stdout is a feature of the line protocol.