Skip to content

Commit

Permalink
Tests: Suppress logging and warnings from temporary profile fixture (#…
Browse files Browse the repository at this point in the history
…5702)

When the test suite is run without specifying a particular test profile,
one is created on the fly using the `TemporaryProfileManager`. This
would create a temporary configuration directory and a temporary profile
which would generate a `UserWarning` and some `REPORT` level log
messages.

This info causes unnecessary noise and the warning even causes `pytest`
to record that the tests issued a warning, but the warning is completely
to be expected and benign, so here we capture the warnings and log
messages.
  • Loading branch information
sphuber authored Oct 19, 2022
1 parent 4b0f8b8 commit 16a5637
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions aiida/manage/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
Testing infrastructure for easy testing of AiiDA plugins.
"""
from contextlib import contextmanager
import contextlib
import os
import shutil
import tempfile
import warnings

from aiida.common.log import override_log_level
from aiida.common.warnings import warn_deprecation
from aiida.manage import configuration, get_manager
from aiida.manage.configuration import settings
Expand Down Expand Up @@ -329,7 +331,11 @@ def create_profile(self):
configuration.CONFIG = None

os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = self.config_dir
settings.set_configuration_directory()

with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=UserWarning)
# This will raise a warning that the ``.aiida`` configuration directory is created.
settings.set_configuration_directory()

manager.unload_profile()
profile_name = self.profile_info['name']
Expand All @@ -339,10 +345,11 @@ def create_profile(self):
config.set_default_profile(profile_name).store()
self._profile = profile

# initialise the profile
profile = manager.load_profile(profile_name)
# initialize the profile storage
profile.storage_cls.migrate(profile)
# Load the new profile and initialize the profile storage
with override_log_level():
profile = manager.load_profile(profile_name)
profile.storage_cls.migrate(profile)

# create the default user for the profile
created, user = User.collection.get_or_create(**get_user_dict(_DEFAULT_PROFILE_INFO))
if created:
Expand Down Expand Up @@ -429,7 +436,7 @@ def has_profile_open(self):
_GLOBAL_TEST_MANAGER = TestManager()


@contextmanager
@contextlib.contextmanager
def test_manager(backend='core.psql_dos', profile_name=None, pgtest=None):
""" Context manager for TestManager objects.
Expand Down

0 comments on commit 16a5637

Please sign in to comment.