Skip to content

Commit

Permalink
Only run junit when there are junit_test targets in the graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
areitz committed Jun 9, 2015
1 parent eb61199 commit c5e0387
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/python/pants/backend/jvm/tasks/junit_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ def _collect_test_targets(self, targets):
java_tests_targets = list(self._test_target_candidates(targets))
tests_from_targets = dict(list(self._calculate_tests_from_targets(java_tests_targets)))

if self._tests_to_run:
# Find matching targets to any requested test.
if java_tests_targets and self._tests_to_run:
# If there are some junit_test targets in the graph, find ones that match the requested
# test(s).
tests_with_targets = {}
for test in self._get_tests_to_run():
# A test might contain #specific_method, which is not needed to find a target.
Expand Down Expand Up @@ -762,7 +763,7 @@ def execute(self):
# that missing sources can be detected early.
for target in targets:
if isinstance(target, junit_tests) and not target.payload.sources.source_paths:
msg = 'JavaTests target {} must include a non-empty set of sources.'.format(target.address.spec)
msg = 'JavaTests target must include a non-empty set of sources.'
raise TargetDefinitionException(target, msg)

self._runner.execute(targets)
1 change: 1 addition & 0 deletions tests/python/pants_test/backend/jvm/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ python_tests(
'src/python/pants/backend/core/targets:common',
'src/python/pants/backend/jvm/targets:java',
'src/python/pants/backend/jvm/tasks:junit_run',
'src/python/pants/backend/python/tasks:python',
'src/python/pants/base:build_file_aliases',
'src/python/pants/base:exceptions',
'src/python/pants/goal:products',
Expand Down
19 changes: 18 additions & 1 deletion tests/python/pants_test/backend/jvm/tasks/test_junit_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pants.backend.core.targets.resources import Resources
from pants.backend.jvm.targets.java_tests import JavaTests
from pants.backend.jvm.tasks.junit_run import JUnitRun
from pants.backend.python.targets.python_tests import PythonTests
from pants.base.build_file_aliases import BuildFileAliases
from pants.base.exceptions import TargetDefinitionException, TaskError
from pants.goal.products import MultipleRootedProducts
Expand Down Expand Up @@ -43,6 +44,7 @@ def alias_groups(self):
return super(JUnitRunnerTest, self).alias_groups.merge(BuildFileAliases.create(
targets={
'java_tests': JavaTests,
'python_tests': PythonTests,
},
))

Expand Down Expand Up @@ -137,6 +139,21 @@ def execute_junit_runner(self, content):
# Finally execute the task.
self.execute(context)

def test_junit_runner_raises_no_error_on_non_junit_target(self):
"""Run pants against a `python_tests` target, but set an option for the `test.junit` task. This
should execute without error.
"""
self.add_to_build_file('foo', dedent('''
python_tests(
name='hello',
sources=['some_file.py'],
)
'''
))
self.set_options(test='#abc')
task = self.create_task(self.context(target_roots=[self.target('foo:hello')]))
task.execute()

def test_empty_sources(self):
self.add_to_build_file('foo', dedent('''
java_tests(
Expand All @@ -147,7 +164,7 @@ def test_empty_sources(self):
))
task = self.create_task(self.context(target_roots=[self.target('foo:empty')]))
with self.assertRaisesRegexp(TargetDefinitionException,
r':empty must include a non-empty set of sources'):
r'must include a non-empty set of sources'):
task.execute()


Expand Down

0 comments on commit c5e0387

Please sign in to comment.