def after_feature(context, feature):
context.test_case.tearDown()
from chroma_core.services.job_scheduler.job_scheduler_client import JobSchedulerClient
from chroma_core.models import Command
JobSchedulerClient.create_host_ssh = context.old_create_host_ssh
JobSchedulerClient.create_targets = context.old_create_targets
JobSchedulerClient.create_filesystem = context.old_create_filesystem
JobSchedulerClient.command_run_jobs = context.old_run_jobs
Command.set_state = context.old_set_state
# If one of the steps fails, an exception will be thrown and the
# transaction rolled back. In which case, this teardown will cause
# a TME which we don't care about.
from django.db.transaction import TransactionManagementError as TME
try:
context.test_case._post_teardown()
except TME:
pass
context.runner.teardown_databases(context.old_db_config)
context.runner.teardown_test_environment()
# As of Django 1.4, teardown_databases() no longer restores the
# original db name in the connection's settings dict. The reasoning
# is documented in https://code.djangoproject.com/ticket/10868, and
# their concerns are understandable. In our case, however, we're not
# going on to do anything here which might affect the production DB.
# Therefore, the following hack restores pre-1.4 behavior:
for connection, old_name, destroy in context.old_db_config[0]:
connection.settings_dict['NAME'] = old_name
from chroma_cli.api import ApiHandle
ApiHandle.ApiClient = context.old_api_client
from chroma_api.authentication import CsrfAuthentication
CsrfAuthentication.is_authenticated = context.old_is_authenticated
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
from chroma_core.services.job_scheduler.job_scheduler_client import JobSchedulerClient
JobSchedulerClient.test_host_contact = context.old_test_host_contact
##--def before_scenario(context, scenario):
#-- # Set up the scenario test environment
#-- context.runner.setup_test_environment()
#-- # We must set up and tear down the entire database between
#-- # scenarios. We can't just use db transactions, as Django's
#-- # TestClient does, if we're doing full-stack tests with Mechanize,
#-- # because Django closes the db connection after finishing the HTTP
#-- # response.
#-- context.old_db_config = context.runner.setup_databases()
#--def after_scenario(context, scenario):
#-- # Tear down the scenario test environment.
#-- context.runner.teardown_databases(context.old_db_config)
#-- context.runner.teardown_test_environment()
#-- # Bob's your uncle.
environment.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录