mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Fix unit test base
This commit is contained in:
parent
038c71213a
commit
a8b52b76b3
3 changed files with 21 additions and 26 deletions
|
|
@ -28,7 +28,6 @@ class AuditingTest(BaseEvenniaTest):
|
|||
session = SESSIONS.session_from_sessid(1) # the real session
|
||||
SESSIONS.login(session, self.account, testmode=True)
|
||||
self.session = session
|
||||
print("session", type(self.session), self.session)
|
||||
|
||||
@patch("evennia.contrib.utils.auditing.server.AUDIT_CALLBACK",
|
||||
"evennia.contrib.utils.auditing.outputs.to_syslog")
|
||||
|
|
|
|||
|
|
@ -949,6 +949,7 @@ class TestPartialTagAttributes(BaseEvenniaTest):
|
|||
"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.prot = {
|
||||
'prototype_key': 'rock',
|
||||
'typeclass': 'evennia.objects.objects.DefaultObject',
|
||||
|
|
|
|||
|
|
@ -131,27 +131,6 @@ class EvenniaTestMixin:
|
|||
room_typeclass = DefaultRoom
|
||||
script_typeclass = DefaultScript
|
||||
|
||||
def save_backups(self):
|
||||
self.backups = (
|
||||
SESSIONS.data_out,
|
||||
SESSIONS.disconnect,
|
||||
settings.DEFAULT_HOME,
|
||||
settings.PROTOTYPE_MODULES,
|
||||
)
|
||||
|
||||
def restore_backups(self):
|
||||
flush_cache()
|
||||
if hasattr(self, "backups"):
|
||||
SESSIONS.data_out = self.backups[0]
|
||||
SESSIONS.disconnect = self.backups[1]
|
||||
settings.DEFAULT_HOME = self.backups[2]
|
||||
settings.PROTOTYPE_MODULES = self.backups[3]
|
||||
|
||||
def mock_sessions(self):
|
||||
SESSIONS.data_out = Mock()
|
||||
SESSIONS.disconnect = Mock()
|
||||
self.mocked_SESSIONS = SESSIONS
|
||||
|
||||
def create_accounts(self):
|
||||
self.account = create.create_account(
|
||||
"TestAccount",
|
||||
|
|
@ -229,8 +208,15 @@ class EvenniaTestMixin:
|
|||
"""
|
||||
Sets up testing environment
|
||||
"""
|
||||
self.save_backups()
|
||||
self.mock_sessions()
|
||||
self.backups = (
|
||||
SESSIONS.data_out,
|
||||
SESSIONS.disconnect,
|
||||
settings.DEFAULT_HOME,
|
||||
settings.PROTOTYPE_MODULES,
|
||||
)
|
||||
SESSIONS.data_out = Mock()
|
||||
SESSIONS.disconnect = Mock()
|
||||
|
||||
self.create_accounts()
|
||||
self.create_rooms()
|
||||
self.create_objs()
|
||||
|
|
@ -239,8 +225,17 @@ class EvenniaTestMixin:
|
|||
self.setup_session()
|
||||
|
||||
def tearDown(self):
|
||||
self.restore_backups()
|
||||
self.teardown_session()
|
||||
flush_cache()
|
||||
try:
|
||||
SESSIONS.data_out = self.backups[0]
|
||||
SESSIONS.disconnect = self.backups[1]
|
||||
settings.DEFAULT_HOME = self.backups[2]
|
||||
settings.PROTOTYPE_MODULES = self.backups[3]
|
||||
except AttributeError as err:
|
||||
raise AttributeError(f"{err}: Teardown error. If you overrode the `setUp()` method "
|
||||
"in your test, make sure you also added `super().setUp()`!")
|
||||
|
||||
del SESSIONS[self.session.sessid]
|
||||
self.teardown_accounts()
|
||||
super().tearDown()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue