From c5ad01c4865fb20af90cff241f595e5fe06e37c2 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 26 Mar 2021 21:53:20 +0100 Subject: Only print verbose logs if pytest -v --- pylint/testutils/lint_module_test.py | 11 +++++++---- tests/test_functional.py | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index 653a6dcdb..158e4f6a5 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -7,9 +7,10 @@ import platform import sys from collections import Counter from io import StringIO -from typing import Dict, List, Tuple +from typing import Dict, List, Optional, Tuple import pytest +from _pytest.config import Config from pylint import checkers from pylint.lint import PyLinter @@ -26,7 +27,7 @@ from pylint.testutils.reporter_for_tests import FunctionalTestReporter class LintModuleTest: maxDiff = None - def __init__(self, test_file: FunctionalTestFile): + def __init__(self, test_file: FunctionalTestFile, config: Optional[Config] = None): _test_reporter = FunctionalTestReporter() self._linter = PyLinter() self._linter.set_reporter(_test_reporter) @@ -41,6 +42,7 @@ class LintModuleTest: except NoFileError: pass self._test_file = test_file + self._config = config def setUp(self): if self._should_be_skipped_due_to_version(): @@ -187,8 +189,9 @@ class LintModuleTest: msg.append("\nUnexpected in testdata:") msg.extend(" %3d: %s" % msg for msg in sorted(unexpected)) # type: ignore error_msg = "\n".join(msg) - error_msg += "\n\nActual pylint output for this file:\n" - error_msg += "\n".join(str(o) for o in actual_output) + if self._config and self._config.getoption("verbose") > 0: + error_msg += "\n\nActual pylint output for this file:\n" + error_msg += "\n".join(str(o) for o in actual_output) return error_msg def error_msg_for_unequal_output(self, expected_lines, received_lines) -> str: diff --git a/tests/test_functional.py b/tests/test_functional.py index 0d015f33e..18706f4f2 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -94,11 +94,11 @@ TEST_WITH_EXPECTED_DEPRECATION = [ @pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES) -def test_functional(test_file, recwarn): +def test_functional(test_file, recwarn, pytestconfig): if UPDATE_FILE.exists(): - lint_test = LintModuleOutputUpdate(test_file) + lint_test = LintModuleOutputUpdate(test_file, pytestconfig) else: - lint_test = testutils.LintModuleTest(test_file) + lint_test = testutils.LintModuleTest(test_file, pytestconfig) lint_test.setUp() lint_test._runTest() warning = None -- cgit v1.2.1