Skip to content

Commit 2e672ea

Browse files
troydaitjprescott
authored andcommitted
Fix Azure#2513: Update logging effect in automation (Azure#3437)
1. Print the executed commands and exit code when a test is failed. 2. Print the failed commands' output. 3. Hide msrest, vcr, or any other logger.
1 parent f3f7f51 commit 2e672ea

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

nose.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[nosetests]
2+
logging-filter=azure.cli.testsdk,vcr_test_base

scripts/automation/tests/nose_helper.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
from __future__ import print_function
77

8+
import os.path
9+
from ..utilities.path import get_repo_root
10+
11+
812
def get_nose_runner(report_folder, parallel=True, process_timeout=600, process_restart=True,
913
xunit_report=False, exclude_integration=True):
1014
"""Create a nose execution method"""
@@ -24,7 +28,7 @@ def _run_nose(test_folders):
2428
or not os.path.isdir(report_folder):
2529
raise ValueError('Report folder {} does not exist'.format(report_folder))
2630

27-
arguments = [__file__, '-v', '--nologcapture']
31+
arguments = [__file__, '-v', '-c', os.path.join(get_repo_root(), 'nose.cfg')]
2832
if parallel:
2933
arguments += ['--processes=-1', '--process-timeout={}'.format(process_timeout)]
3034
if process_restart:
@@ -36,12 +40,8 @@ def _run_nose(test_folders):
3640
else:
3741
test_report = ''
3842

39-
if exclude_integration:
40-
arguments += ['--ignore-files=integration*']
41-
4243
debug_file = os.path.join(report_folder, 'test-debug.log')
4344
arguments += ['--debug-log={}'.format(debug_file)]
44-
arguments += ['--nologcapture']
4545
arguments.extend(test_folders)
4646
result = nose.run(argv=arguments)
4747

src/azure-cli-testsdk/azure/cli/testsdk/base.py

+10-20
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
from __future__ import print_function
7-
import datetime
86
import unittest
97
import os
108
import inspect
@@ -29,27 +27,17 @@
2927
from .utilities import create_random_name
3028
from .decorators import live_only
3129

32-
logger = logging.getLogger('azuer.cli.testsdk')
30+
logger = logging.getLogger('azure.cli.testsdk')
3331

3432

3533
class IntegrationTestBase(unittest.TestCase):
3634
def __init__(self, method_name):
3735
super(IntegrationTestBase, self).__init__(method_name)
3836
self.diagnose = os.environ.get(ENV_TEST_DIAGNOSE, None) == 'True'
3937

40-
def cmd(self, command, checks=None, expect_failure=False):
41-
if self.diagnose:
42-
begin = datetime.datetime.now()
43-
print('\nExecuting command: {}'.format(command))
44-
45-
result = execute(command, expect_failure=expect_failure)
46-
47-
if self.diagnose:
48-
duration = datetime.datetime.now() - begin
49-
print('\nCommand accomplished in {} s. Exit code {}.\n{}'.format(
50-
duration.total_seconds(), result.exit_code, result.output))
51-
52-
return result.assert_with_checks(checks)
38+
@classmethod
39+
def cmd(cls, command, checks=None, expect_failure=False):
40+
return execute(command, expect_failure=expect_failure).assert_with_checks(checks)
5341

5442
def create_random_name(self, prefix, length): # pylint: disable=no-self-use
5543
return create_random_name(prefix=prefix, length=length)
@@ -238,17 +226,21 @@ def _custom_request_query_matcher(cls, r1, r2):
238226

239227
class ExecutionResult(object): # pylint: disable=too-few-public-methods
240228
def __init__(self, command, expect_failure=False, in_process=True):
241-
logger.info('Execute command %s', command)
242229
if in_process:
243230
self._in_process_execute(command)
244231
else:
245232
self._out_of_process_execute(command)
246233

247234
if expect_failure and self.exit_code == 0:
248-
raise AssertionError('The command is expected to fail but it doesn\'.')
235+
logger.error('Command "%s" => %d. (It did not fail as expected) Output: %s', command,
236+
self.exit_code, self.output)
237+
raise AssertionError('The command did not fail as it was expected.')
249238
elif not expect_failure and self.exit_code != 0:
239+
logger.error('Command "%s" => %d. Output: %s', command, self.exit_code, self.output)
250240
raise AssertionError('The command failed. Exit code: {}'.format(self.exit_code))
251241

242+
logger.info('Command "%s" => %d.', command, self.exit_code)
243+
252244
self.json_value = None
253245
self.skip_assert = os.environ.get(ENV_SKIP_ASSERT, None) == 'True'
254246

@@ -260,8 +252,6 @@ def assert_with_checks(self, *args):
260252
elif callable(each):
261253
checks.append(each)
262254

263-
logger.info('Checkers to be executed %s', len(checks))
264-
265255
if not self.skip_assert:
266256
for c in checks:
267257
c(self)

src/azure-cli-testsdk/azure/cli/testsdk/vcr_test_base.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tempfile
1717
import traceback
18+
import logging
1819
from random import choice
1920
from string import digits, ascii_lowercase
2021

@@ -45,6 +46,7 @@
4546
MOCKED_TENANT_ID = '00000000-0000-0000-0000-000000000000'
4647
MOCKED_STORAGE_ACCOUNT = 'dummystorage'
4748

49+
logger = logging.getLogger('vcr_test_base')
4850

4951
# MOCK METHODS
5052

@@ -109,7 +111,7 @@ def _mock_subscriptions(self): # pylint: disable=unused-argument
109111

110112

111113
def _mock_user_access_token(_, _1, _2, _3): # pylint: disable=unused-argument
112-
return ('Bearer', 'top-secret-token-for-you', None)
114+
return 'Bearer', 'top-secret-token-for-you', None
113115

114116

115117
def _mock_operation_delay(_):
@@ -284,7 +286,6 @@ def __init__(self, test_file, test_name, run_live=False, debug=False, debug_vcr=
284286
self.exception = CLIError('No recorded result provided for {}.'.format(self.test_name))
285287

286288
if debug_vcr:
287-
import logging
288289
logging.basicConfig()
289290
vcr_log = logging.getLogger('vcr')
290291
vcr_log.setLevel(logging.INFO)
@@ -427,8 +428,11 @@ def cmd(self, command, checks=None, allowed_exceptions=None,
427428
cli_main(command_list, file=output)
428429
except Exception as ex: # pylint: disable=broad-except
429430
ex_msg = str(ex)
431+
logger.error('Command "%s" => %s. Output: %s', command, ex_msg, output.getvalue())
430432
if not next((x for x in allowed_exceptions if x in ex_msg), None):
431433
raise ex
434+
435+
logger.info('Command "%s" => %s.', command, 'success')
432436
self._track_executed_commands(command_list)
433437
result = output.getvalue().strip()
434438
output.close()

0 commit comments

Comments
 (0)