RemoteTestResult
Extend unittest.TestResult to record events in the child processes so they can be replayed in the parent process. Events include things like which tests succeeded or failed.
Attributes
| Attribute | Type | Description |
|---|---|---|
| failures | [DummyList](dummylist.md?sid=django_test_runner_dummylist) = DummyList() | A dummy list used to replace standard failure storage to reduce memory usage in child processes. |
| errors | [DummyList](dummylist.md?sid=django_test_runner_dummylist) = DummyList() | A dummy list used to replace standard error storage to reduce memory usage in child processes. |
| skipped | [DummyList](dummylist.md?sid=django_test_runner_dummylist) = DummyList() | A dummy list used to replace standard skip storage to reduce memory usage in child processes. |
| expectedFailures | [DummyList](dummylist.md?sid=django_test_runner_dummylist) = DummyList() | A dummy list used to replace standard expected failure storage to reduce memory usage in child processes. |
| unexpectedSuccesses | [DummyList](dummylist.md?sid=django_test_runner_dummylist) = DummyList() | A dummy list used to replace standard unexpected success storage to reduce memory usage in child processes. |
| events | list = [] | A list of recorded test event tuples used to replay results in the parent process. |
| test_index | int | The zero-based index of the current test being run, derived from the total number of tests run. |
Constructor
Signature
def RemoteTestResult(
*args: any,
**kwargs: any
)
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list passed to the parent unittest.TestResult constructor. |
| **kwargs | any | Arbitrary keyword arguments passed to the parent unittest.TestResult constructor. |
Methods
test_index()
@classmethod
def test_index() - > int
Calculates the current test index based on the total number of tests run.
Returns
| Type | Description |
|---|---|
int | The zero-based index of the current test. |
check_picklable()
@classmethod
def check_picklable(
test: unittest.TestCase,
err: tuple
)
Verifies that exception info can be pickled, providing helpful guidance or warnings if serialization fails.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that raised the exception. |
| err | tuple | The sys.exc_info() tuple containing the exception type, value, and traceback. |
check_subtest_picklable()
@classmethod
def check_subtest_picklable(
test: unittest.TestCase,
subtest: unittest.TestCase
)
Validates that a subtest object is picklable to ensure it can be passed back from a worker process.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The parent test case. |
| subtest | unittest.TestCase | The subtest instance to validate. |
startTestRun()
@classmethod
def startTestRun()
Signals the beginning of a test run and records the event.
stopTestRun()
@classmethod
def stopTestRun()
Signals the completion of a test run and records the event.
startTest()
@classmethod
def startTest(
test: unittest.TestCase
)
Records the start of an individual test case.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that is starting. |
stopTest()
@classmethod
def stopTest(
test: unittest.TestCase
)
Records the completion of an individual test case.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that has finished. |
addDuration()
@classmethod
def addDuration(
test: unittest.TestCase,
elapsed: float
)
Logs the execution duration for a specific test.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that was timed. |
| elapsed | float | The time in seconds taken to run the test. |
addError()
@classmethod
def addError(
test: unittest.TestCase,
err: tuple
)
Records an error event, ensuring the error is picklable for parallel processing.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case or error holder where the error occurred. |
| err | tuple | The exception information tuple. |
addFailure()
@classmethod
def addFailure(
test: unittest.TestCase,
err: tuple
)
Records a test failure event after verifying the failure details can be pickled.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that failed. |
| err | tuple | The exception information tuple representing the failure. |
addSubTest()
@classmethod
def addSubTest(
test: unittest.TestCase,
subtest: unittest.TestCase,
err: tuple
)
Records a subtest result if an error occurred, verifying picklability of both the error and the subtest.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The parent test case. |
| subtest | unittest.TestCase | The specific subtest instance. |
| err | tuple | The exception info if the subtest failed, or None if it succeeded. |
addSuccess()
@classmethod
def addSuccess(
test: unittest.TestCase
)
Records a successful test completion event.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that passed. |
addSkip()
@classmethod
def addSkip(
test: unittest.TestCase,
reason: string
)
Records a skipped test event along with the reason for skipping.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that was skipped. |
| reason | string | The explanation provided for skipping the test. |
addExpectedFailure()
@classmethod
def addExpectedFailure(
test: unittest.TestCase,
err: tuple
)
Records an expected failure, optionally stripping the traceback if tblib is not available to ensure picklability.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that failed as expected. |
| err | tuple | The exception information tuple. |
addUnexpectedSuccess()
@classmethod
def addUnexpectedSuccess(
test: unittest.TestCase
)
Records an event where a test decorated with expectedFailure actually passed.
Parameters
| Name | Type | Description |
|---|---|---|
| test | unittest.TestCase | The test case that unexpectedly succeeded. |
wasSuccessful()
@classmethod
def wasSuccessful() - > boolean
Tells whether or not this result was a success.
Returns
| Type | Description |
|---|---|
boolean | True if no errors, failures, subtest failures, or unexpected successes were recorded; False otherwise. |