Skip to content

Commit

Permalink
Only print verbose logs if pytest -v
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored and Pierre-Sassoulas committed Mar 26, 2021
1 parent cb3ea62 commit 09dce02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
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
Expand All @@ -26,7 +27,7 @@
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)
Expand All @@ -41,6 +42,7 @@ def __init__(self, test_file: FunctionalTestFile):
except NoFileError:
pass
self._test_file = test_file
self._config = config

def setUp(self):
if self._should_be_skipped_due_to_version():
Expand Down Expand Up @@ -187,8 +189,9 @@ def error_msg_for_unequal_messages(
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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def get_tests():


@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
Expand Down

0 comments on commit 09dce02

Please sign in to comment.