Skip to content

Commit

Permalink
Change PantsIntegrationTest to be hermetic by default (pantsbuild#1…
Browse files Browse the repository at this point in the history
…0672)

Several refactors:

* Make `hermetic` a class property rather than classmethod. Default to True.
* Rename `use_pantsd_env_var` to a class property `use_pantsd`. Removes the env var mechanism as we no longer use that. Defaults to pantsd being used.
* Rename `hermetic_env_whitelist` to `hermetic_env_allowlist`, and make it a class property.
* Add type hints.
* Enforce kwargs.
* Remove `do_command()` in favor of `self.run_pants()`. It does the same thing. We want to simplify.
* Remove the unused `file_renamed`. We generally are moving in the direction of our integration tests creating their own environment, rather than mutating the build root (e.g. testprojects). This wasn't being used.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Aug 23, 2020
1 parent c7c30db commit 496a680
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 226 deletions.
2 changes: 1 addition & 1 deletion build-support/bin/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReferenceGenerator:
To run use:
./pants \
--backend-packages="-['internal_backend.rules_for_testing', 'internal_backend.utilities']" \
--backend-packages="-['internal_backend.utilities']" \
--backend-packages="+['pants.backend.python.lint.bandit', \
'pants.backend.python.lint.pylint', 'pants.backend.codegen.protobuf.python', \
'pants.backend.awslambda.python']" \
Expand Down
1 change: 0 additions & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ backend_packages.add = [
"pants.backend.python.lint.flake8",
"pants.backend.python.lint.isort",
"pants.backend.python.typecheck.mypy",
"internal_backend.rules_for_testing",
"internal_backend.utilities",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_arithmetic():

def _run_tests(self, tmpdir_relative, *more_args: str) -> PantsResult:
command = [
"--backend-packages=pants.backend.python",
"test",
"--use-coverage",
f"{tmpdir_relative}/src/python/project:tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def upper_case(s):
(src_root2 / "BUILD").write_text("python_library()")
result = self.run_pants(
[
"--backend-packages=pants.backend.python",
(
f"--source-root-patterns=['/{tmpdir_relative}/src_root1', "
f"'/{tmpdir_relative}/src_root2']"
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/base/exception_sink_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@


class ExceptionSinkIntegrationTest(PantsDaemonIntegrationTestBase):
hermetic = False

def _assert_unhandled_exception_log_matches(self, pid, file_contents, namespace):
self.assertRegex(
file_contents,
Expand Down
10 changes: 7 additions & 3 deletions src/python/pants/base/exiter_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class ExiterIntegrationTest(PantsIntegrationTest):

@ensure_daemon
def test_unicode_containing_exception(self):
"""Test whether we can run a single target without special flags."""
pants_run = self.run_pants(["run", "testprojects/src/python/unicode/compilation_failure"])
pants_run = self.run_pants(
[
"--backend-packages=pants.backend.python",
"run",
"testprojects/src/python/unicode/compilation_failure",
]
)
self.assert_failure(pants_run)

self.assertIn("import sys¡", pants_run.stderr)
1 change: 0 additions & 1 deletion src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ python_binary(
'build-support/flake8',
'build-support/mypy',
'build-support/regexes',
'pants-plugins/src/python/internal_backend/rules_for_testing',
'pants-plugins/src/python/internal_backend/utilities',
],
# We depend on twitter.common libraries that trigger pex warnings for not properly declaring their
Expand Down
19 changes: 17 additions & 2 deletions src/python/pants/build_graph/subproject_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ class SubprojectIntegrationTest(PantsIntegrationTest):
def test_subproject(self) -> None:
with harness():
# If `--subproject-roots` are not specified, we expect a failure.
self.assert_failure(self.run_pants(["dependencies", "--transitive", SUBPROJ_SPEC]))
self.assert_failure(
self.run_pants(
[
"--backend-packages=pants.backend.python",
"dependencies",
"--transitive",
SUBPROJ_SPEC,
]
)
)

# The same command should succeed when `--subproject-roots` are specified.
self.assert_success(
self.run_pants(
[
"--backend-packages=pants.backend.python",
f"--subproject-roots={SUBPROJ_ROOT}",
"dependencies",
"--transitive",
Expand All @@ -94,6 +104,11 @@ def test_subproject(self) -> None:
# Both relative and absolute dependencies should work.
self.assert_success(
self.run_pants(
[f"--subproject-roots={SUBPROJ_ROOT}", "dependencies", f"{SUBPROJ_ROOT}:local"]
[
"--backend-packages=pants.backend.python",
f"--subproject-roots={SUBPROJ_ROOT}",
"dependencies",
f"{SUBPROJ_ROOT}:local",
]
)
)
16 changes: 13 additions & 3 deletions src/python/pants/core/goals/fmt_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ class FmtIntegrationTest(PantsIntegrationTest):
def test_fmt_then_edit(self):
f = "examples/src/python/example/hello/greet/greet.py"
with self.temporary_workdir() as workdir:
run = lambda: self.run_pants_with_workdir(["fmt", f], workdir=workdir)

def run() -> None:
result = self.run_pants_with_workdir(
[
"--backend-packages=['pants.backend.python', 'pants.backend.python.lint.black']",
"fmt",
f,
],
workdir=workdir,
)
self.assert_success(result)

# Run once to start up, and then capture the file content.
self.assert_success(run())
run()
good_content = read_file(f)

# Edit the file.
Expand All @@ -25,5 +35,5 @@ def test_fmt_then_edit(self):
assert good_content != read_file(f)

# Re-run and confirm that the file was fixed.
self.assert_success(run())
run()
assert good_content == read_file(f)
1 change: 1 addition & 0 deletions src/python/pants/engine/internals/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python_integration_tests(
uses_pants_run=True,
dependencies=[
'examples/src/python/example:hello_directory',
'pants-plugins/src/python/internal_backend/rules_for_testing',
],
timeout=180,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_visualize_to(self):
with temporary_dir() as destdir:
args = [
f"--native-engine-visualize-to={destdir}",
"--backend-packages=pants.backend.python",
"list",
"examples/src/python/example/hello/greet",
]
Expand All @@ -25,6 +26,7 @@ def test_visualize_to(self):
@ensure_daemon
def test_graceful_termination(self):
args = [
"--backend-packages=['pants.backend.python', 'internal_backend.rules_for_testing']",
"list-and-die-for-testing",
"examples/src/python/example/hello/greet",
]
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/help/help_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_help_advanced(self):
assert "--pants-bootstrapdir" in pants_run.stdout

def test_help_all(self):
command = ["help-all"]
command = ["--backend-packages=pants.backend.python", "help-all"]
pants_run = self.run_pants(command=command)
self.assert_success(pants_run)
all_help = json.loads(pants_run.stdout)
Expand Down
9 changes: 3 additions & 6 deletions src/python/pants/option/options_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

@pytest.mark.skip("Skip until https://github.com/pantsbuild/pants/issues/10206")
class TestOptionsIntegration(PantsIntegrationTest):
@classmethod
def hermetic(cls) -> bool:
return True

def test_options_works_at_all(self) -> None:
self.assert_success(self.run_pants(["options"]))

Expand Down Expand Up @@ -302,15 +298,16 @@ def test_pants_symlink_workdirs(self) -> None:
physical_workdir = f"{physical_workdir_base}/{safe_filename_from_path(symlink_workdir)}"

pants_run = self.run_pants_with_workdir(
[f"--pants-physical-workdir-base={physical_workdir_base}", "help"], symlink_workdir
[f"--pants-physical-workdir-base={physical_workdir_base}", "help"],
workdir=symlink_workdir,
)
self.assert_success(pants_run)
# Make sure symlink workdir is pointing to physical workdir
self.assertTrue(os.readlink(symlink_workdir) == physical_workdir)

self.run_pants_with_workdir(
[f"--pants-physical-workdir-base={physical_workdir_base}", "clean-all"],
symlink_workdir,
workdir=symlink_workdir,
)
# Make sure both physical_workdir and symlink_workdir are empty after running clean-all
self.assertTrue(not os.listdir(symlink_workdir) and not os.listdir(physical_workdir))
Loading

0 comments on commit 496a680

Please sign in to comment.