-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #32114 -- Subtest pickle issue with ParallelTestRunner #13599
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,43 @@ def debug(self, error): | |
pdb.post_mortem(traceback) | ||
|
||
|
||
class TestCaseDTO: | ||
""" | ||
The ParallelTestSuite requires that all test cases be pickleable. When a | ||
SubTest fails with an exception, it's pickled and shipped back to the main | ||
process to be displayed to the user. Unfortunately, Django's TestCases | ||
aren't always pickleable (for example, they may contain an instance of | ||
django.test.Client, which can't be cleanly pickled if an exception was | ||
raised by the view). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The When dealing with normal tests, the data in However, when a subtest is encountered, |
||
|
||
Luckily the outer TestRunner only cares about a small subset of the fields | ||
on TestCase, and those are usually pickleable. We use this object to pluck | ||
out those fields, discarding extra unpickleable members. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docstring spends a lot of time explainining the problem. I think it can be edited down to something a little more terse to make the class more maintainable. Perhaps:
|
||
""" | ||
|
||
def __init__(self, test): | ||
self._inner_id = test.id() | ||
self._inner_str = str(test) | ||
self._inner_shortDescription = test.shortDescription() | ||
if hasattr(test, "test_case"): | ||
self.test_case = TestCaseDTO(test.test_case) | ||
if hasattr(test, "_subDescription"): | ||
self._inner_subDescription = test._subDescription() | ||
|
||
def _subDescription(self): | ||
"""conforming to _SubTest""" | ||
return self._inner_subDescription | ||
|
||
def id(self): | ||
return self._inner_id | ||
|
||
def shortDescription(self): | ||
return self._inner_shortDescription | ||
|
||
def __str__(self): | ||
return self._inner_str | ||
|
||
|
||
class RemoteTestResult: | ||
""" | ||
Record information about which tests have succeeded and which have failed. | ||
|
@@ -237,6 +274,7 @@ def addSubTest(self, test, subtest, err): | |
# Follow Python 3.5's implementation of unittest.TestResult.addSubTest() | ||
# by not doing anything when a subtest is successful. | ||
if err is not None: | ||
subtest = TestCaseDTO(subtest) | ||
# Call check_picklable() before check_subtest_picklable() since | ||
# check_picklable() performs the tblib check. | ||
self.check_picklable(test, err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does DTO stand for? I think it'd be better to use a spelled out name for this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.wikipedia.org/wiki/Data_transfer_object
Happy to rename for clarity