Skip to content

Commit

Permalink
test: reset logger after tests (#936)
Browse files Browse the repository at this point in the history
Co-authored-by: alambare-csgroup <aubin.lambare@csgroup.eu>
  • Loading branch information
sbrunato and alambare-csgroup committed Nov 22, 2023
1 parent a3f8296 commit c7d09b5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_cli.py
Expand Up @@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import random
import re
Expand All @@ -40,7 +41,6 @@
download,
eodag,
search_crunch,
setup_logging,
)
from tests.units import test_core
from tests.utils import mock, no_blanks, write_eodag_conf_with_fake_credentials
Expand Down Expand Up @@ -80,11 +80,13 @@ def setUp(self):

def tearDown(self):
super(TestEodagCli, self).tearDown()
# Default logging: no logging but still displays progress bars
setup_logging(1)
# stop Mock and remove tmp config dir
self.expanduser_mock.stop()
self.tmp_home_dir.cleanup()
# reset logging
logger = logging.getLogger("eodag")
logger.handlers = []
logger.level = 0

def test_eodag_without_args(self):
"""Calling eodag without arguments should print help message"""
Expand Down
4 changes: 4 additions & 0 deletions tests/units/test_apis_plugins.py
Expand Up @@ -692,6 +692,10 @@ def test_plugins_apis_cds_logging(self):
client = self.api_plugin._get_cds_client(**auth_dict)
self.assertEqual(client.logger.level, logging.DEBUG)

logger = logging.getLogger("eodag")
logger.handlers = []
logger.level = 0

def test_plugins_apis_cds_query_dates_missing(self):
"""CdsApi.query must use default dates if missing"""
# given start & stop
Expand Down
8 changes: 8 additions & 0 deletions tests/units/test_core.py
Expand Up @@ -19,6 +19,7 @@
import copy
import glob
import json
import logging
import os
import shutil
import unittest
Expand Down Expand Up @@ -76,6 +77,10 @@ def tearDownClass(cls):
# stop Mock and remove tmp config dir
cls.expanduser_mock.stop()
cls.tmp_home_dir.cleanup()
# reset logging
logger = logging.getLogger("eodag")
logger.handlers = []
logger.level = 0


class TestCore(TestCoreBase):
Expand Down Expand Up @@ -1512,6 +1517,9 @@ def test__search_by_id(

found = self.dag._search_by_id(uid="foo", productType="bar", provider="baz")

from eodag.utils.logging import get_logging_verbose

_ = get_logging_verbose()
# get_search_plugins
mock_get_search_plugins.assert_called_once_with(
self.dag._plugins_manager, product_type="bar", provider="baz"
Expand Down
12 changes: 12 additions & 0 deletions tests/units/test_utils.py
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import copy
import logging
import os
import sys
import unittest
Expand All @@ -41,6 +42,17 @@


class TestUtils(unittest.TestCase):
def setUp(self) -> None:
super(TestUtils, self).setUp()
setup_logging(verbose=1)

def tearDown(self) -> None:
super(TestUtils, self).tearDown()
# reset logging
logger = logging.getLogger("eodag")
logger.handlers = []
logger.level = 0

def test_utils_get_timestamp(self):
"""get_timestamp must return a UNIX timestamp"""
# Date to timestamp to date, this assumes the date is in UTC
Expand Down

0 comments on commit c7d09b5

Please sign in to comment.