testing: Use a random database name when running backend tests.

This decreases risk of conflicts between running the backend and
casper test suites.

Part of #1977.
This commit is contained in:
Umair Khan 2017-04-11 11:05:43 +05:00 committed by Tim Abbott
parent 65b96aab0c
commit c9140dfa4c
1 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,8 @@
from __future__ import print_function
from functools import partial
import random
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, \
Text, Type
from unittest import loader, runner # type: ignore # Mypy cannot pick these up.
@ -361,6 +363,7 @@ class Runner(DiscoverRunner):
# in `zerver.tests.test_templates`.
self.shallow_tested_templates = set() # type: Set[str]
template_rendered.connect(self.on_template_rendered)
self.database_id = random.randint(1, 10000)
def get_resultclass(self):
# type: () -> Type[TestResult]
@ -381,6 +384,19 @@ class Runner(DiscoverRunner):
# type: () -> Set[str]
return self.shallow_tested_templates
def setup_test_environment(self, *args, **kwargs):
# type: (*Any, **Any) -> Any
destroy_test_databases(self.database_id)
create_test_databases(self.database_id)
return super(Runner, self).setup_test_environment(*args, **kwargs)
def teardown_test_environment(self, *args, **kwargs):
# type: (*Any, **Any) -> Any
# No need to pass the database id now. It will be picked up
# automatically through settings.
destroy_test_databases()
return super(Runner, self).teardown_test_environment(*args, **kwargs)
def run_tests(self, test_labels, extra_tests=None,
full_suite=False, **kwargs):
# type: (List[str], Optional[List[TestCase]], bool, **Any) -> Tuple[bool, List[str]]