Skip to content

Commit

Permalink
[internal] Remove badreq target only used for tests (pantsbuild#14275)
Browse files Browse the repository at this point in the history
This causes issues with the upcoming multiple resolves feature, as every `python_requirement` _must_ belong to a resolve. `badreq` causes that resolve to fail.

The fix is to simply create the bad target during test-time.

[ci skip-rust]
  • Loading branch information
Eric-Arellano authored Jan 27, 2022
1 parent 1a2fa31 commit cc4a963
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 50 deletions.
2 changes: 0 additions & 2 deletions testprojects/src/python/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

files(name="bad_requirements_directory", sources=["bad_requirements/**/*"])

files(name="build_file_imports_function_directory", sources=["build_file_imports_function/**/*"])

files(name="build_file_imports_module_directory", sources=["build_file_imports_module/**/*"])
Expand Down
11 changes: 0 additions & 11 deletions testprojects/src/python/bad_requirements/BUILD

This file was deleted.

9 changes: 0 additions & 9 deletions testprojects/src/python/bad_requirements/use_badreq.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/python/pants_test/pantsd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python_tests(
sources=["pantsd_integration_test.py"],
dependencies=[
"testprojects/src/python:hello_directory",
"testprojects/src/python:bad_requirements_directory",
"testprojects/src/python:print_env_directory",
],
timeout=2100,
Expand Down
57 changes: 30 additions & 27 deletions tests/python/pants_test/pantsd/pantsd_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,28 +596,23 @@ def test_dependencies_swap(self):
)
"""
)
with self.pantsd_successful_run_context() as ctx:
with temporary_dir(".") as directory:
safe_file_dump(os.path.join(directory, "A.py"), mode="w")
safe_file_dump(os.path.join(directory, "B.py"), mode="w")

if directory.startswith("./"):
directory = directory[2:]
with self.pantsd_successful_run_context() as ctx, temporary_dir(".") as directory:
safe_file_dump(os.path.join(directory, "A.py"), mode="w")
safe_file_dump(os.path.join(directory, "B.py"), mode="w")

def list_and_verify():
result = ctx.runner(["list", f"{directory}:"])
ctx.checker.assert_started()
result.assert_success()
expected_targets = {f"{directory}:{target}" for target in ("A", "B")}
self.assertEqual(expected_targets, set(result.stdout.strip().split("\n")))
if directory.startswith("./"):
directory = directory[2:]

with open(os.path.join(directory, "BUILD"), "w") as f:
f.write(template.format(a_deps='dependencies = [":B"],', b_deps=""))
list_and_verify()
def list_and_verify(a_deps: str, b_deps: str) -> None:
Path(directory, "BUILD").write_text(template.format(a_deps=a_deps, b_deps=b_deps))
result = ctx.runner(["list", f"{directory}:"])
ctx.checker.assert_started()
result.assert_success()
expected_targets = {f"{directory}:{target}" for target in ("A", "B")}
assert expected_targets == set(result.stdout.strip().split("\n"))

with open(os.path.join(directory, "BUILD"), "w") as f:
f.write(template.format(a_deps="", b_deps='dependencies = [":A"],'))
list_and_verify()
list_and_verify(a_deps='dependencies = [":B"],', b_deps="")
list_and_verify(a_deps="", b_deps='dependencies = [":A"],')

def test_concurrent_overrides_pantsd(self):
"""Tests that the --concurrent flag overrides the --pantsd flag, because we don't allow
Expand All @@ -638,18 +633,26 @@ def test_unhandled_exceptions_only_log_exceptions_once(self):
This is a regression test for the most glaring case of https://github.com/pantsbuild/pants/issues/7597.
"""
with self.pantsd_run_context(success=False) as ctx:
result = ctx.runner(["run", "testprojects/src/python/bad_requirements:use_badreq"])
with self.pantsd_run_context(success=False) as ctx, temporary_dir(".") as directory:
Path(directory, "BUILD").write_text(
dedent(
"""\
python_requirement(name="badreq", requirements=["badreq==99.99.99"])
pex_binary(name="pex", dependencies=[":badreq"])
"""
)
)
result = ctx.runner(["package", f"{directory}:pex"])
ctx.checker.assert_running()
result.assert_failure()
# Assert that the desired exception has been triggered once.
self.assertRegex(result.stderr, r"ERROR:.*badreq==99.99.99")
# Assert that it has only been triggered once.
self.assertNotIn(
"During handling of the above exception, another exception occurred:",
result.stderr,
assert (
"During handling of the above exception, another exception occurred:"
not in result.stderr
)
self.assertNotIn(
"pants.bin.daemon_pants_runner._PantsRunFinishedWithFailureException: Terminated with 1",
result.stderr,
assert (
"pants.bin.daemon_pants_runner._PantsRunFinishedWithFailureException: Terminated with 1"
not in result.stderr
)

0 comments on commit cc4a963

Please sign in to comment.