Don't print to stdout when executing hacking checks

The way the hacking tests _run_check works, it ends up evaluating
python code in a context where all of our stdout capture has been
undone. The pep8 check_all method *also* prints out the errors found,
not only accumulating them for later. We can patch out the method
doing that to keep this from leaking through the test output, which
only causes confusion.

Change-Id: I9be4801352c4977504d95123d01bcbe309f22347
This commit is contained in:
Sean Dague 2016-09-22 07:47:39 -04:00
parent dc2f4f88ac
commit 15b392a67b
1 changed files with 5 additions and 1 deletions

View File

@ -343,7 +343,11 @@ class HackingTestCase(test.NoDBTestCase):
lines = textwrap.dedent(code).strip().splitlines(True)
checker = pep8.Checker(filename=filename, lines=lines)
checker.check_all()
# NOTE(sdague): the standard reporter has printing to stdout
# as a normal part of check_all, which bleeds through to the
# test output stream in an unhelpful way. This blocks that printing.
with mock.patch('pep8.StandardReport.get_file_results'):
checker.check_all()
checker.report._deferred_print.sort()
return checker.report._deferred_print