beeware / cricket

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

Runner now supports embedded test suites in build_suite() result. #23

Closed lensvol closed 11 years ago

lensvol commented 11 years ago

There was a problem, where Django test discoverer threw an exception while trying to process TestSuites embedded in build_suite()'s output:

File "C:\Coding\Soft\Envs\kinder\Lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Coding\Soft\Envs\kinder\Lib\site-packages\south\management\commands\test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "C:\Coding\Soft\Envs\kinder\Lib\site-packages\django\core\management\commands\test.py", line 72, in handle
failures = test_runner.run_tests(test_labels)
File "C:\Coding\Soft\Envs\kinder\Lib\site-packages\cricket\django\discoverer.py", line 25, in run_tests
parts = test.id().split('.')
AttributeError: 'TestSuite' object has no attribute 'id'

Although you can always click "Continue" and ignore this exceptions, it hides embedded test suites from discovery and may prevent cricket from finding special test instances (e.g. doctests).

Included changeset treats build_suite() output as a trivial list of leafs and nodes, with nodes being additional test suites, which in turn can include other suites etc.

freakboy3742 commented 11 years ago

Hi @lensvol

It isn't clear to me exactly how you're reproducing this problem. I don't see this error on my sample projects that I use for testing; can you provide a sample project (or an example of exactly how to write a sample project) that will exhibit this problem?

lensvol commented 11 years ago

I'll try to add it later today. It seems that it's related to doctests in one of our libraries (btw, Django==1.4, unittest2==0.5.1, Python 2.6).

lensvol commented 11 years ago

Managed to replicate it using Windows, Django 1.5.4, Python 2.6.6, unittest2 0.5.1 or standard unittest from Django:

mkvirtualenv djtest workon djtest python django-admin.py startproject djtest pip install cricket python manage.py test --testrunner=cricket.django.discoverer.TestDiscoverer

...and after many tests were discovered, it ended with:

AttributeError: 'TestSuite' object has no attribute 'id'

freakboy3742 commented 11 years ago

Ah - now I can reproduce. It looks like a manual install of unittest2 is the magic ingredient -- If you leave unittest2 out of the stack, you don't get the bug.

freakboy3742 commented 11 years ago

It turns out you've discovered an bug in Django's pre-1.5 test suite reordering. There's an isinstance check that is looking for unittest.TestSuite, but due to the way Django 1.5 ships a copy of unittest2, that class check doesn't check the base unittest.TestSuite.

This code has been replaced in Django 1.6 as part of the transition to native unittest2 discovery, and the removal of the builtin unittest2 package, so the bug won't be fixed in the 1.5 branch. So - it looks like the approach you've described in this pull request is essentially correct -- allow for Suites to be returned in the build_suite output.

I've got a couple of stylistic issues with the patch as presented, but I can correct them locally when I commit.