Closed lensvol closed 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?
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).
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'
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.
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.
There was a problem, where Django test discoverer threw an exception while trying to process TestSuites embedded in build_suite()'s output:
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.