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

Properly resolve transitive dependencies in V2 Pytest runner #7720

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -17,7 +17,8 @@
Snapshot, UrlToFetch)
from pants.engine.isolated_process import (ExecuteProcessRequest, ExecuteProcessResult,
FallibleExecuteProcessResult)
from pants.engine.legacy.graph import TransitiveHydratedTarget
from pants.engine.legacy.graph import (BuildFileAddresses, TransitiveHydratedTarget,
TransitiveHydratedTargets)
from pants.engine.rules import optionable_rule, rule
from pants.engine.selectors import Get
from pants.rules.core.core_test_model import Status, TestResult
@@ -58,7 +59,12 @@ def run_python_test(transitive_hydrated_target, pytest, python_setup, source_roo
digest = Digest('61bb79384db0da8c844678440bd368bcbfac17bbdb865721ad3f9cb0ab29b629', 1826945)
pex_snapshot = yield Get(Snapshot, UrlToFetch(url, digest))

all_targets = [target_root] + [dep.root for dep in transitive_hydrated_target.dependencies]
# TODO(7726): replace this with a proper API to get the `closure` for a
# TransitiveHydratedTarget.
transitive_hydrated_targets = yield Get(
TransitiveHydratedTargets, BuildFileAddresses((target_root.address,))
)
all_targets = transitive_hydrated_targets.closure

# Produce a pex containing pytest and all transitive 3rdparty requirements.
all_requirements = []
@@ -36,3 +36,19 @@ python_tests(
'3rdparty/python:future',
],
)

python_library(
name = 'transitive_dep',
source = 'example_transitive_source.py',
dependencies = [
':example_lib',
],
)

python_tests(
name = 'target_with_transitive_dep',
sources = ['test_with_transitive_dep.py'],
dependencies = [
':transitive_dep',
],
)
@@ -0,0 +1,5 @@
from pants.dummies.example_source import add_two


def add_four(x):
return add_two(x) + 2
@@ -0,0 +1,7 @@
from __future__ import absolute_import

from pants.dummies.example_transitive_source import add_four


def test_external_method():
assert add_four(2) == 6
@@ -181,6 +181,29 @@ def test_thirdparty_dep(self):
""")
)

def test_transitive_dep(self):
pants_run = self.run_passing_pants_test([
'testprojects/tests/python/pants/dummies:target_with_transitive_dep',
])
self.assert_fuzzy_string_match(
pants_run.stdout_data,
dedent("""\
testprojects/tests/python/pants/dummies:target_with_transitive_dep stdout:
============================= test session starts ==============================
platform SOME_TEXT
rootdir: SOME_TEXT
plugins: SOME_TEXT
collected 1 item
pants/dummies/test_with_transitive_dep.py . [100%]
=========================== 1 passed in SOME_TEXT ===========================
testprojects/tests/python/pants/dummies:target_with_transitive_dep ..... SUCCESS
""")
)

def test_mixed_python_tests(self):
pants_run = self.run_failing_pants_test([
'testprojects/tests/python/pants/dummies:failing_target',
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.