From d79ab7f9ea0cd4fa15e200737c95eb10e3b359bc Mon Sep 17 00:00:00 2001 From: Norberto Arrieta Date: Wed, 6 Mar 2024 16:08:51 -0800 Subject: [PATCH] Run unit tests with pytest on Python >= 3.10 (#3081) * Run unit tests with pytest on Python >= 3.10 --------- Co-authored-by: narrieta --- .github/workflows/ci_pr.yml | 11 +- ci/nosetests.sh | 8 +- ci/pytest.sh | 19 +++ test-requirements.txt | 5 +- tests/common/test_logger.py | 2 +- tests/common/test_telemetryevent.py | 30 ++--- tests/ga/test_cgroupconfigurator.py | 115 +---------------- tests/ga/test_cgroupconfigurator_sudo.py | 157 +++++++++++++++++++++++ tests/ga/test_extension.py | 4 - tests/test_agent.py | 7 + 10 files changed, 216 insertions(+), 142 deletions(-) create mode 100755 ci/pytest.sh create mode 100644 tests/ga/test_cgroupconfigurator_sudo.py diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml index 2e1ac5ab4..f470b4428 100644 --- a/.github/workflows/ci_pr.yml +++ b/.github/workflows/ci_pr.yml @@ -156,11 +156,14 @@ jobs: pylint $PYLINT_OPTIONS $PYLINT_FILES - - name: Test with nosetests - if: contains(fromJSON('["3.10", "3.11"]'), matrix.python-version) == false && (success() || (failure() && steps.install-dependencies.outcome == 'success')) + - name: Execute Unit Tests + if: success() || (failure() && steps.install-dependencies.outcome == 'success') run: | - ./ci/nosetests.sh - exit $? + if [[ "${{ matrix.python-version }}" =~ ^3\.[1-9][0-9]+$ ]]; then + ./ci/pytest.sh + else + ./ci/nosetests.sh + fi - name: Compile Coverage if: matrix.python-version == '3.9' diff --git a/ci/nosetests.sh b/ci/nosetests.sh index faefd902a..15b83860e 100755 --- a/ci/nosetests.sh +++ b/ci/nosetests.sh @@ -5,18 +5,18 @@ set -u EXIT_CODE=0 echo "=========================================" -echo "nosetests -a '!requires_sudo' output" +echo "**** nosetests non-sudo tests ****" echo "=========================================" -nosetests -a '!requires_sudo' tests $NOSEOPTS || EXIT_CODE=$(($EXIT_CODE || $?)) +nosetests --ignore-files test_cgroupconfigurator_sudo.py tests $NOSEOPTS || EXIT_CODE=$(($EXIT_CODE || $?)) echo EXIT_CODE no_sudo nosetests = $EXIT_CODE [[ -f .coverage ]] && \ sudo mv .coverage coverage.$(uuidgen).no_sudo.data echo "=========================================" -echo "nosetests -a 'requires_sudo' output" +echo "**** nosetests sudo tests ****" echo "=========================================" -sudo env "PATH=$PATH" nosetests -a 'requires_sudo' tests $NOSEOPTS || EXIT_CODE=$(($EXIT_CODE || $?)) +sudo env "PATH=$PATH" nosetests tests/ga/test_cgroupconfigurator_sudo.py $NOSEOPTS || EXIT_CODE=$(($EXIT_CODE || $?)) echo EXIT_CODE with_sudo nosetests = $EXIT_CODE [[ -f .coverage ]] && \ diff --git a/ci/pytest.sh b/ci/pytest.sh new file mode 100755 index 000000000..c166e5853 --- /dev/null +++ b/ci/pytest.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -u + +EXIT_CODE=0 + +echo "=========================================" +echo "**** pytest *** non-sudo tests ****" +echo "=========================================" +pytest --ignore-glob '*/test_cgroupconfigurator_sudo.py' --verbose tests || EXIT_CODE=$(($EXIT_CODE || $?)) +echo EXIT_CODE pytests non-sudo = $EXIT_CODE + +echo "=========================================" +echo "**** pytest *** sudo tests ****" +echo "=========================================" +sudo env "PATH=$PATH" pytest --verbose tests/ga/test_cgroupconfigurator_sudo.py || EXIT_CODE=$(($EXIT_CODE || $?)) +echo EXIT_CODE pytests sudo = $EXIT_CODE + +exit "$EXIT_CODE" diff --git a/test-requirements.txt b/test-requirements.txt index 2b9467870..0d653912e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,8 +3,9 @@ mock==2.0.0; python_version == '2.6' mock==3.0.5; python_version >= '2.7' and python_version <= '3.5' mock==4.0.2; python_version >= '3.6' distro; python_version >= '3.8' -nose -nose-timer; python_version >= '2.7' +nose; python_version <= '3.9' +nose-timer; python_version >= '2.7' and python_version <= '3.9' +pytest; python_version >= '3.10' # Pinning the wrapt requirement to 1.12.0 due to the bug - https://github.com/GrahamDumpleton/wrapt/issues/188 wrapt==1.12.0; python_version > '2.6' and python_version < '3.6' diff --git a/tests/common/test_logger.py b/tests/common/test_logger.py index d792eb857..4e72e0010 100644 --- a/tests/common/test_logger.py +++ b/tests/common/test_logger.py @@ -15,7 +15,6 @@ # Requires Python 2.6+ and Openssl 1.0+ # -import json # pylint: disable=unused-import import os import tempfile from datetime import datetime, timedelta @@ -49,6 +48,7 @@ def tearDown(self): AgentTestCase.tearDown(self) logger.reset_periodic() logger.DEFAULT_LOGGER.appenders *= 0 + logger.set_prefix(None) fileutil.rm_dirs(self.event_dir) @patch('azurelinuxagent.common.logger.Logger.verbose') diff --git a/tests/common/test_telemetryevent.py b/tests/common/test_telemetryevent.py index ce232dab0..27a808ddc 100644 --- a/tests/common/test_telemetryevent.py +++ b/tests/common/test_telemetryevent.py @@ -19,23 +19,23 @@ from tests.lib.tools import AgentTestCase -def get_test_event(name="DummyExtension", op="Unknown", is_success=True, duration=0, version="foo", evt_type="", is_internal=False, - message="DummyMessage", eventId=1): - event = TelemetryEvent(eventId, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX") - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Name, name)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Version, str(version))) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.IsInternal, is_internal)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Operation, op)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.OperationSuccess, is_success)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Message, message)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Duration, duration)) - event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.ExtensionType, evt_type)) - return event - - class TestTelemetryEvent(AgentTestCase): + @staticmethod + def _get_test_event(name="DummyExtension", op="Unknown", is_success=True, duration=0, version="foo", evt_type="", is_internal=False, + message="DummyMessage", eventId=1): + event = TelemetryEvent(eventId, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX") + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Name, name)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Version, str(version))) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.IsInternal, is_internal)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Operation, op)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.OperationSuccess, is_success)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Message, message)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.Duration, duration)) + event.parameters.append(TelemetryEventParam(GuestAgentExtensionEventsSchema.ExtensionType, evt_type)) + return event + def test_contains_works_for_TelemetryEvent(self): - test_event = get_test_event(message="Dummy Event") + test_event = TestTelemetryEvent._get_test_event(message="Dummy Event") self.assertTrue(GuestAgentExtensionEventsSchema.Name in test_event) self.assertTrue(GuestAgentExtensionEventsSchema.Version in test_event) diff --git a/tests/ga/test_cgroupconfigurator.py b/tests/ga/test_cgroupconfigurator.py index 63c6ee90b..82c86c956 100644 --- a/tests/ga/test_cgroupconfigurator.py +++ b/tests/ga/test_cgroupconfigurator.py @@ -26,20 +26,17 @@ import time import threading -from nose.plugins.attrib import attr - from azurelinuxagent.common import conf from azurelinuxagent.ga.cgroup import AGENT_NAME_TELEMETRY, MetricsCounter, MetricValue, MetricsCategory, CpuCgroup from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator, DisableCgroups from azurelinuxagent.ga.cgroupstelemetry import CGroupsTelemetry from azurelinuxagent.common.event import WALAEventOperation -from azurelinuxagent.common.exception import CGroupsException, ExtensionError, ExtensionErrorCodes, \ - AgentMemoryExceededException +from azurelinuxagent.common.exception import CGroupsException, AgentMemoryExceededException from azurelinuxagent.common.future import ustr from azurelinuxagent.common.utils import shellutil, fileutil from tests.lib.mock_environment import MockCommand from tests.lib.mock_cgroup_environment import mock_cgroup_environment, UnitFilePaths -from tests.lib.tools import AgentTestCase, patch, mock_sleep, i_am_root, data_dir, is_python_version_26_or_34, skip_if_predicate_true +from tests.lib.tools import AgentTestCase, patch, mock_sleep, data_dir, is_python_version_26_or_34, skip_if_predicate_true from tests.lib.miscellaneous_tools import format_processes, wait_for @@ -526,112 +523,6 @@ def test_start_extension_command_should_disable_cgroups_and_invoke_the_command_d self.assertEqual(len(CGroupsTelemetry._tracked), 0, "No cgroups should have been created") - @skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.") - @attr('requires_sudo') - @patch('time.sleep', side_effect=lambda _: mock_sleep()) - def test_start_extension_command_should_not_use_fallback_option_if_extension_fails(self, *args): - self.assertTrue(i_am_root(), "Test does not run when non-root") - - with self._get_cgroup_configurator() as configurator: - pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below - - command = "ls folder_does_not_exist" - - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: - with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", wraps=subprocess.Popen) as popen_patch: - with self.assertRaises(ExtensionError) as context_manager: - configurator.start_extension_command( - extension_name="Microsoft.Compute.TestExtension-1.2.3", - command=command, - cmd_name="test", - timeout=300, - shell=True, - cwd=self.tmp_dir, - env={}, - stdout=stdout, - stderr=stderr) - - extension_calls = [args[0] for (args, _) in popen_patch.call_args_list if command in args[0]] - - self.assertEqual(1, len(extension_calls), "The extension should have been invoked exactly once") - self.assertIn("systemd-run", extension_calls[0], - "The first call to the extension should have used systemd") - - self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginUnknownFailure) - self.assertIn("Non-zero exit code", ustr(context_manager.exception)) - # The scope name should appear in the process output since systemd-run was invoked and stderr - # wasn't truncated. - self.assertIn("Running scope as unit", ustr(context_manager.exception)) - - @skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.") - @attr('requires_sudo') - @patch('time.sleep', side_effect=lambda _: mock_sleep()) - @patch("azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN", 5) - def test_start_extension_command_should_not_use_fallback_option_if_extension_fails_with_long_output(self, *args): - self.assertTrue(i_am_root(), "Test does not run when non-root") - - with self._get_cgroup_configurator() as configurator: - pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below - - long_output = "a"*20 # large enough to ensure both stdout and stderr are truncated - long_stdout_stderr_command = "echo {0} && echo {0} >&2 && ls folder_does_not_exist".format(long_output) - - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: - with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", wraps=subprocess.Popen) as popen_patch: - with self.assertRaises(ExtensionError) as context_manager: - configurator.start_extension_command( - extension_name="Microsoft.Compute.TestExtension-1.2.3", - command=long_stdout_stderr_command, - cmd_name="test", - timeout=300, - shell=True, - cwd=self.tmp_dir, - env={}, - stdout=stdout, - stderr=stderr) - - extension_calls = [args[0] for (args, _) in popen_patch.call_args_list if long_stdout_stderr_command in args[0]] - - self.assertEqual(1, len(extension_calls), "The extension should have been invoked exactly once") - self.assertIn("systemd-run", extension_calls[0], - "The first call to the extension should have used systemd") - - self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginUnknownFailure) - self.assertIn("Non-zero exit code", ustr(context_manager.exception)) - # stdout and stderr should have been truncated, so the scope name doesn't appear in stderr - # even though systemd-run ran - self.assertNotIn("Running scope as unit", ustr(context_manager.exception)) - - @attr('requires_sudo') - def test_start_extension_command_should_not_use_fallback_option_if_extension_times_out(self, *args): # pylint: disable=unused-argument - self.assertTrue(i_am_root(), "Test does not run when non-root") - - with self._get_cgroup_configurator() as configurator: - pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below - - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: - with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: - with patch("azurelinuxagent.ga.extensionprocessutil.wait_for_process_completion_or_timeout", - return_value=[True, None, 0]): - with patch("azurelinuxagent.ga.cgroupapi.SystemdCgroupsApi._is_systemd_failure", - return_value=False): - with self.assertRaises(ExtensionError) as context_manager: - configurator.start_extension_command( - extension_name="Microsoft.Compute.TestExtension-1.2.3", - command="date", - cmd_name="test", - timeout=300, - shell=True, - cwd=self.tmp_dir, - env={}, - stdout=stdout, - stderr=stderr) - - self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginHandlerScriptTimedout) - self.assertIn("Timeout", ustr(context_manager.exception)) - @skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.") @patch('time.sleep', side_effect=lambda _: mock_sleep()) def test_start_extension_command_should_capture_only_the_last_subprocess_output(self, _): @@ -1024,4 +915,4 @@ def test_check_agent_memory_usage_should_raise_a_cgroups_exception_when_the_limi tracked_metrics.return_value = metrics configurator.check_agent_memory_usage() - self.assertIn("The agent memory limit {0} bytes exceeded".format(conf.get_agent_memory_quota()), ustr(context_manager.exception), "An incorrect exception was raised") \ No newline at end of file + self.assertIn("The agent memory limit {0} bytes exceeded".format(conf.get_agent_memory_quota()), ustr(context_manager.exception), "An incorrect exception was raised") diff --git a/tests/ga/test_cgroupconfigurator_sudo.py b/tests/ga/test_cgroupconfigurator_sudo.py new file mode 100644 index 000000000..30db19408 --- /dev/null +++ b/tests/ga/test_cgroupconfigurator_sudo.py @@ -0,0 +1,157 @@ +# Copyright 2018 Microsoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Requires Python 2.4+ and Openssl 1.0+ +# + +from __future__ import print_function + +import contextlib +import subprocess +import tempfile + +from azurelinuxagent.ga.cgroupconfigurator import CGroupConfigurator +from azurelinuxagent.ga.cgroupstelemetry import CGroupsTelemetry +from azurelinuxagent.common.exception import ExtensionError, ExtensionErrorCodes +from azurelinuxagent.common.future import ustr +from tests.lib.mock_cgroup_environment import mock_cgroup_environment +from tests.lib.tools import AgentTestCase, patch, mock_sleep, i_am_root, is_python_version_26_or_34, skip_if_predicate_true + + +class CGroupConfiguratorSystemdTestCaseSudo(AgentTestCase): + @classmethod + def tearDownClass(cls): + CGroupConfigurator._instance = None + AgentTestCase.tearDownClass() + + @contextlib.contextmanager + def _get_cgroup_configurator(self, initialize=True, enable=True, mock_commands=None): + CGroupConfigurator._instance = None + configurator = CGroupConfigurator.get_instance() + CGroupsTelemetry.reset() + with mock_cgroup_environment(self.tmp_dir) as mock_environment: + if mock_commands is not None: + for command in mock_commands: + mock_environment.add_command(command) + configurator.mocks = mock_environment + if initialize: + if not enable: + with patch.object(configurator, "enable"): + configurator.initialize() + else: + configurator.initialize() + yield configurator + + @skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it") + @patch('time.sleep', side_effect=lambda _: mock_sleep()) + def test_start_extension_command_should_not_use_fallback_option_if_extension_fails(self, *args): + self.assertTrue(i_am_root(), "Test does not run when non-root") + + with self._get_cgroup_configurator() as configurator: + pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below + + command = "ls folder_does_not_exist" + + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: + with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", wraps=subprocess.Popen) as popen_patch: + with self.assertRaises(ExtensionError) as context_manager: + configurator.start_extension_command( + extension_name="Microsoft.Compute.TestExtension-1.2.3", + command=command, + cmd_name="test", + timeout=300, + shell=True, + cwd=self.tmp_dir, + env={}, + stdout=stdout, + stderr=stderr) + + extension_calls = [args[0] for (args, _) in popen_patch.call_args_list if command in args[0]] + + self.assertEqual(1, len(extension_calls), "The extension should have been invoked exactly once") + self.assertIn("systemd-run", extension_calls[0], + "The first call to the extension should have used systemd") + + self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginUnknownFailure) + self.assertIn("Non-zero exit code", ustr(context_manager.exception)) + # The scope name should appear in the process output since systemd-run was invoked and stderr + # wasn't truncated. + self.assertIn("Running scope as unit", ustr(context_manager.exception)) + + @skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it") + @patch('time.sleep', side_effect=lambda _: mock_sleep()) + @patch("azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN", 5) + def test_start_extension_command_should_not_use_fallback_option_if_extension_fails_with_long_output(self, *args): + self.assertTrue(i_am_root(), "Test does not run when non-root") + + with self._get_cgroup_configurator() as configurator: + pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below + + long_output = "a"*20 # large enough to ensure both stdout and stderr are truncated + long_stdout_stderr_command = "echo {0} && echo {0} >&2 && ls folder_does_not_exist".format(long_output) + + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: + with patch("azurelinuxagent.ga.cgroupapi.subprocess.Popen", wraps=subprocess.Popen) as popen_patch: + with self.assertRaises(ExtensionError) as context_manager: + configurator.start_extension_command( + extension_name="Microsoft.Compute.TestExtension-1.2.3", + command=long_stdout_stderr_command, + cmd_name="test", + timeout=300, + shell=True, + cwd=self.tmp_dir, + env={}, + stdout=stdout, + stderr=stderr) + + extension_calls = [args[0] for (args, _) in popen_patch.call_args_list if long_stdout_stderr_command in args[0]] + + self.assertEqual(1, len(extension_calls), "The extension should have been invoked exactly once") + self.assertIn("systemd-run", extension_calls[0], + "The first call to the extension should have used systemd") + + self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginUnknownFailure) + self.assertIn("Non-zero exit code", ustr(context_manager.exception)) + # stdout and stderr should have been truncated, so the scope name doesn't appear in stderr + # even though systemd-run ran + self.assertNotIn("Running scope as unit", ustr(context_manager.exception)) + + def test_start_extension_command_should_not_use_fallback_option_if_extension_times_out(self, *args): # pylint: disable=unused-argument + self.assertTrue(i_am_root(), "Test does not run when non-root") + + with self._get_cgroup_configurator() as configurator: + pass # release the mocks used to create the test CGroupConfigurator so that they do not conflict the mock Popen below + + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stdout: + with tempfile.TemporaryFile(dir=self.tmp_dir, mode="w+b") as stderr: + with patch("azurelinuxagent.ga.extensionprocessutil.wait_for_process_completion_or_timeout", + return_value=[True, None, 0]): + with patch("azurelinuxagent.ga.cgroupapi.SystemdCgroupsApi._is_systemd_failure", + return_value=False): + with self.assertRaises(ExtensionError) as context_manager: + configurator.start_extension_command( + extension_name="Microsoft.Compute.TestExtension-1.2.3", + command="date", + cmd_name="test", + timeout=300, + shell=True, + cwd=self.tmp_dir, + env={}, + stdout=stdout, + stderr=stderr) + + self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginHandlerScriptTimedout) + self.assertIn("Timeout", ustr(context_manager.exception)) diff --git a/tests/ga/test_extension.py b/tests/ga/test_extension.py index 62bd11099..95b2427bc 100644 --- a/tests/ga/test_extension.py +++ b/tests/ga/test_extension.py @@ -63,10 +63,6 @@ SUCCESS_CODE_FROM_STATUS_FILE = 1 -def do_not_run_test(): - return True - - def raise_system_exception(): raise Exception diff --git a/tests/test_agent.py b/tests/test_agent.py index f892f090e..cbf223aa5 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -17,6 +17,8 @@ import os.path +import azurelinuxagent.common.logger as logger + from azurelinuxagent.agent import parse_args, Agent, usage, AgentCommands from azurelinuxagent.common import conf from azurelinuxagent.ga import logcollector, cgroupconfigurator @@ -101,6 +103,11 @@ class TestAgent(AgentTestCase): + def tearDown(self): + # These tests instantiate the Agent class, which has the side effect + # of initializing the global logger and conf objects; reset them. + logger.DEFAULT_LOGGER = logger.Logger() + conf.__conf__.values = {} def test_accepts_configuration_path(self): conf_path = os.path.join(data_dir, "test_waagent.conf")