CleanCut / green

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

Prevent green from hanging on internal failure during error reporting. #214

Closed charles-l closed 4 years ago

charles-l commented 4 years ago

green currently hangs when trying to run with a doctests in the load_tests call:

(save the following to a file named test_doctest.py):

import unittest                                                                                                                                                                                                                                                                                                                
import doctest                                                                                                                                                                                                                                                                                                                 

def f():                                                                                                                                                                                                                                                                                                                       
    '''                                                                                                                                                                                                                                                                                                                        
    >>> f()                                                                                                                                                                                                                                                                                                                    
    2                                                                                                                                                                                                                                                                                                                          
    '''                                                                                                                                                                                                                                                                                                                        
    return 2                                                                                                                                                                                                                                                                                                                   

def load_tests(loader, tests, ignore):                                                                                                                                                                                                                                                                                         
    return doctest.DocTestSuite('test_doctest')

This patch catches the exception that's thrown in the worker and reports it back. Before, the workers would bail and become defunct processes, while the scheduler process would hang because it was waiting for a result from the queue (which never showed up)

This doesn't fix the underlying issue with doctest (unfortunately), but it at least prints the error and prevents green from hanging.

charles-l commented 4 years ago

Oh, interesting -- it looks like the bug is actually in the GreenTestLoader class. When I run poolRunner('test_doctest', ...) (so it imports it directly without wrapping in the GreenTestLoader), the tests run as expected. I'll try and dig into that issue and see if I can't fix it...

CleanCut commented 4 years ago

Fascinating! Testing for the win... 😉 I'm excited to hear what you find.

CleanCut commented 4 years ago

Fun fact: I started looking into this and ended up almost adding doctest support to green. I've just got a final issue that I'm stuck on that is driving me crazy.

CleanCut commented 4 years ago

Got doctest support working! I want to finish writing up some new tests for it (naturally), and then I'll put together a new release.

Edit: Unfortunately, I found another showstopper bug while writing tests. I'm stuck again. 😢

Update: Fixed that one too! (Don't do from doctest import DocTestCase in a test module, because DocTestCase is a subclass of TestCase and gets caught up in unittest test discovery.

CleanCut commented 4 years ago

Support for doctests was added in version 3.1.0, just released.

charles-l commented 4 years ago

Oh sweet -- thanks for adding this support! I'm excited to start using it :)

CleanCut commented 4 years ago

Let me know how it goes!