test_runner: Replace django.test.TestCase with unittest.TestCase.

The supertype uses unittest.TestCase. We conform to that for
type compatibility.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-07-27 12:31:38 -04:00
committed by Tim Abbott
parent c68c07619f
commit 8b29b37227

View File

@@ -10,7 +10,6 @@ from unittest.result import TestResult
from django.conf import settings from django.conf import settings
from django.db import ProgrammingError, connections from django.db import ProgrammingError, connections
from django.test import TestCase
from django.test import runner as django_runner from django.test import runner as django_runner
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
from django.test.signals import template_rendered from django.test.signals import template_rendered
@@ -56,10 +55,10 @@ class TextTestResult(runner.TextTestResult):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.failed_tests: List[str] = [] self.failed_tests: List[str] = []
def addInstrumentation(self, test: TestCase, data: Dict[str, Any]) -> None: def addInstrumentation(self, test: unittest.TestCase, data: Dict[str, Any]) -> None:
append_instrumentation_data(data) append_instrumentation_data(data)
def startTest(self, test: TestCase) -> None: def startTest(self, test: unittest.TestCase) -> None:
TestResult.startTest(self, test) TestResult.startTest(self, test)
self.stream.write(f"Running {test.id()}\n") self.stream.write(f"Running {test.id()}\n")
self.stream.flush() self.stream.flush()
@@ -77,7 +76,7 @@ class TextTestResult(runner.TextTestResult):
test_name = args[0].id() test_name = args[0].id()
self.failed_tests.append(test_name) self.failed_tests.append(test_name)
def addSkip(self, test: TestCase, reason: str) -> None: def addSkip(self, test: unittest.TestCase, reason: str) -> None:
TestResult.addSkip(self, test, reason) TestResult.addSkip(self, test, reason)
self.stream.write(f"** Skipping {test.id()}: {reason}\n") self.stream.write(f"** Skipping {test.id()}: {reason}\n")
self.stream.flush() self.stream.flush()
@@ -89,7 +88,7 @@ class RemoteTestResult(django_runner.RemoteTestResult):
base class. base class.
""" """
def addInstrumentation(self, test: TestCase, data: Dict[str, Any]) -> None: def addInstrumentation(self, test: unittest.TestCase, data: Dict[str, Any]) -> None:
# Some elements of data['info'] cannot be serialized. # Some elements of data['info'] cannot be serialized.
if "info" in data: if "info" in data:
del data["info"] del data["info"]
@@ -377,7 +376,7 @@ class Runner(DiscoverRunner):
def run_tests( def run_tests(
self, self,
test_labels: List[str], test_labels: List[str],
extra_tests: Optional[List[TestCase]] = None, extra_tests: Optional[List[unittest.TestCase]] = None,
full_suite: bool = False, full_suite: bool = False,
include_webhooks: bool = False, include_webhooks: bool = False,
**kwargs: Any, **kwargs: Any,