The error can be shown with a specific series of skipped and non-skipped
tests. I attached a minimal example project that demonstrates the issue.
This used to work in Django 1.7, and doesn't work in any Django versions
later than 1.7. It is caused, according to a Git bisect, by
https://github.com/django/django/commit/da9fe5c717c179a9e881a40efd3bfe36a21bf4a6.
--
Ticket URL: <https://code.djangoproject.com/ticket/25860>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "t.tar.bz2" added.
Minimal test project
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
If you raise `SkipTest` in `setUpClass()` after calling `super()`, then
I'd think the database setup in `TestCase.setUpClass()` happens but not
the teardown in `TestCase.tearDownClass`? If so, I'm not sure there's much
Django can do about the issue. Any suggestions? Can you raise `SkipTest`
before calling `super()`?
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:1>
Comment (by carljm):
Without digging into it more I don't know if this is something that would
need to be fixed in Django or in stdlib unittest, but ISTM that ideally
even if `SkipTest` is raised after `setUpClass`, the testing framework
ought to be responsible to make sure that `tearDownClass` is still called
regardless.
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:2>
Comment (by jonashaag):
I agree with carljm.
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:3>
Comment (by jonashaag):
From the Python docs:
If an exception is raised during a setUpClass then the tests in the class
are not run **and the tearDownClass is not run**. Skipped classes will not
have setUpClass or tearDownClass run. If the exception is a SkipTest
exception then the class will be reported as having been skipped instead
of as an error.
Looks like nothing's wrong with Django here.
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:4>
* keywords: regression =>
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
* component: Testing framework => Documentation
Comment:
How about a [https://github.com/django/django/pull/5777 documentation
patch] to raise awareness?
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"a5619f7ed3bc2ca07b428fa0abfaaff088378f48" a5619f7e]:
{{{
#!CommitTicketReference repository=""
revision="a5619f7ed3bc2ca07b428fa0abfaaff088378f48"
Fixed #25860 -- Documented a transaction leak possiblity in TestCase.
Thanks Jonas Haag for report and review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"35b5e11a98580e5f5045be36e8901699e39d2867" 35b5e11]:
{{{
#!CommitTicketReference repository=""
revision="35b5e11a98580e5f5045be36e8901699e39d2867"
[1.9.x] Fixed #25860 -- Documented a transaction leak possiblity in
TestCase.
Thanks Jonas Haag for report and review.
Backport of a5619f7ed3bc2ca07b428fa0abfaaff088378f48 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25860#comment:7>