Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging for V2 test scheduler as temporary workaround until V2 UI is finished #7729

Merged
11 changes: 11 additions & 0 deletions src/python/pants/rules/core/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

import logging

from pants.backend.python.rules.python_test_runner import PyTestResult
from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE
from pants.build_graph.address import Address
Expand All @@ -16,6 +18,10 @@
from pants.rules.core.core_test_model import Status, TestResult


# TODO(#6004): use proper Logging singleton, rather than static logger.
logger = logging.getLogger(__name__)


class Test(Goal):
"""Runs tests."""

Expand Down Expand Up @@ -66,7 +72,12 @@ def coordinator_of_tests(target):
#if isinstance(target.adaptor, PythonTestsAdaptor):
# See https://github.com/pantsbuild/pants/issues/4535
if target.adaptor.type_alias == 'python_tests':
logger.info("Starting tests: {}".format(target.address.reference()))
result = yield Get(PyTestResult, HydratedTarget, target)
logger.info("Tests {}: {}".format(
"succeeded" if result.status == Status.SUCCESS else "failed",
target.address.reference(),
))
yield TestResult(status=result.status, stdout=result.stdout, stderr=result.stderr)
else:
raise Exception("Didn't know how to run tests for type {}".format(target.adaptor.type_alias))
Expand Down
11 changes: 6 additions & 5 deletions tests/python/pants_test/rules/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from builtins import str
from textwrap import dedent

Expand Down Expand Up @@ -104,17 +105,17 @@ def test_stderr(self):

def test_coordinator_python_test(self):
target_adaptor = PythonTestsAdaptor(type_alias='python_tests')

result = run_rule(coordinator_of_tests, HydratedTarget(Address.parse("some/target"), target_adaptor, ()), {
(PyTestResult, HydratedTarget): lambda _: PyTestResult(status=Status.FAILURE, stdout='foo', stderr=''),
})
with self.captured_logging(logging.INFO):
result = run_rule(coordinator_of_tests, HydratedTarget(Address.parse("some/target"), target_adaptor, ()), {
(PyTestResult, HydratedTarget): lambda _: PyTestResult(status=Status.FAILURE, stdout='foo', stderr=''),
})

self.assertEqual(result, TestResult(status=Status.FAILURE, stdout='foo', stderr=''))

def test_coordinator_unknown_test(self):
target_adaptor = PythonTestsAdaptor(type_alias='unknown_tests')

with self.assertRaises(Exception) as cm:
with self.captured_logging(logging.INFO), self.assertRaises(Exception) as cm:
run_rule(coordinator_of_tests, HydratedTarget(Address.parse("some/target"), target_adaptor, ()), {
(PyTestResult, HydratedTarget): lambda _: PyTestResult(status=Status.FAILURE, stdout='foo', stderr=''),
})
Expand Down
27 changes: 10 additions & 17 deletions tests/python/pants_test/rules/test_test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@

class TestIntegrationTest(PantsRunIntegrationTest):

def run_pants(self, args):
def run_pants(self, trailing_args):
args = [
'--no-v1',
'--v2',
'--no-colors',
'--level=warn',
'test',
] + trailing_args
# Set TERM=dumb to stop pytest from trying to be clever and wrap lines which may interfere with
# our golden data.
return super(TestIntegrationTest, self).run_pants(args, extra_env={'TERM': 'dumb'})
Expand All @@ -33,26 +40,12 @@ def assert_fuzzy_string_match(self, got, want):
self.assertTrue(got_line.endswith(want_parts[1]), 'Line {} Want "{}" to end with "{}"'.format(line_number, got_line, want_parts[1]))

def run_passing_pants_test(self, trailing_args):
args = [
'--no-v1',
'--v2',
'--no-colors',
'test',
] + trailing_args

pants_run = self.run_pants(args)
pants_run = self.run_pants(trailing_args)
self.assert_success(pants_run)
return pants_run

def run_failing_pants_test(self, trailing_args):
args = [
'--no-v1',
'--v2',
'--no-colors',
'test',
] + trailing_args

pants_run = self.run_pants(args)
pants_run = self.run_pants(trailing_args)
self.assert_failure(pants_run)
self.assertEqual('Tests failed\n', pants_run.stderr_data)

Expand Down