Skip to content

Commit

Permalink
Depend on conftest and data files in Python tests BUILD files
Browse files Browse the repository at this point in the history
Bazel requires that all the files used in a test run should be
represented in the transitive dependencies specified for the test
target. For py_test, it means srcs, deps and data.

Bazel enforces this constraint by creating a "runfiles" directory,
symbolic links files in the dependency closure and run the test in the
"runfiles" directory, so that the test shouldn't see files not in the
dependency graph.

Unfortunately, the constraint does not apply for a large number of
Python tests, due to pytest (>=3.9.0, <6.0) resolving these symbolic
links during test collection and effectively "breaks out" of the
runfiles tree.

pytest >= 6.0 introduces a breaking change and removed the symbolic link
resolving behaviour, see pytest pull request
pytest-dev/pytest#6523 for more context.

Currently, we are underspecifying dependencies in a lot of BUILD files
and thus blocking us from updating to newer pytest (for Python 3.10
support). This change hopefully fixes all of them, and at least those in
CI, by adding data or source dependencies (mostly for conftest.py-s)
where needed.
  • Loading branch information
Riatre committed Jul 12, 2022
1 parent 7995bc7 commit 6406cda
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 89 deletions.
17 changes: 17 additions & 0 deletions dashboard/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,41 @@ py_library(
),
)

py_library(
name = "conftest",
srcs = ["tests/conftest.py"],
deps = ["//python/ray/tests:conftest"],
)

py_test_run_all_subdirectory(
size = "medium",
include = ["**/test*.py"],
exclude = ["modules/test/**", "modules/node/tests/test_node.py", "tests/test_dashboard.py"],
extra_srcs = [],
data = [
"modules/job/tests/backwards_compatibility_scripts/test_backwards_compatibility.sh",
"modules/job/tests/pip_install_test-0.5-py3-none-any.whl",
"modules/snapshot/snapshot_schema.json",
"modules/tests/test_config_files/basic_runtime_env.yaml",
] + glob([
"modules/job/tests/subprocess_driver_scripts/*.py",
]),
deps = [":conftest"],
tags = ["exclusive", "team:serve"],
)

py_test(
name = "test_node",
size = "medium",
srcs = ["modules/node/tests/test_node.py"],
deps = [":conftest"],
tags = ["exclusive", "team:serve"],
)

py_test(
name = "test_dashboard",
size = "medium",
srcs = ["tests/test_dashboard.py"],
deps = [":conftest"],
tags = ["exclusive", "team:serve"],
)
5 changes: 5 additions & 0 deletions python/ray/autoscaler/aws/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "example",
data = glob(["example-*.yaml"]),
visibility = ["//python/ray/tests:__pkg__"],
)
5 changes: 5 additions & 0 deletions python/ray/autoscaler/azure/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "example",
data = glob(["example-*.yaml"]),
visibility = ["//python/ray/tests:__pkg__"],
)
5 changes: 5 additions & 0 deletions python/ray/autoscaler/gcp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "example",
data = glob(["example-*.yaml"]),
visibility = ["//python/ray/tests:__pkg__"],
)
5 changes: 5 additions & 0 deletions python/ray/autoscaler/local/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "example",
data = glob(["example-*.yaml"]),
visibility = ["//python/ray/tests:__pkg__"],
)
16 changes: 7 additions & 9 deletions python/ray/data/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
# --------------------------------------------------------------------
load("//bazel:python.bzl", "py_test_module_list")

SRCS = [] + select({
"@bazel_tools//src/conditions:windows": glob([
"**/conftest.py",
]),
"//conditions:default": [],
})
py_library(
name = "conftest",
srcs = ["tests/conftest.py"],
deps = ["//python/ray/tests:conftest"],
)

py_test(
name = "test_preprocessors",
size = "small",
srcs = ["tests/test_preprocessors.py"],
tags = ["team:ml", "exclusive", "ray_air"],
deps = ["//:ray_lib"],
deps = ["//:ray_lib", ":conftest"],
)

py_test_module_list(
Expand All @@ -26,7 +25,6 @@ py_test_module_list(
exclude=["tests/test_preprocessors.py"]
),
size = "large",
extra_srcs = SRCS,
tags = ["team:core", "exclusive"],
deps = ["//:ray_lib"],
deps = ["//:ray_lib", ":conftest"],
)
9 changes: 9 additions & 0 deletions python/ray/experimental/packaging/example_pkg/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
filegroup(
name = "example_pkg",
data = [
"ray_pkg.yaml",
] + glob([
"my_pkg/**/*.py",
]),
visibility = ["//python/ray/tests:__pkg__"],
)
6 changes: 6 additions & 0 deletions python/ray/serve/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ py_library(

serve_tests_srcs = glob(["tests/**/*.py"])

filegroup(
name = "test_config_files",
data = glob(["tests/test_config_files/**/*"]),
)

py_test(
name = "test_api",
size = "medium",
Expand Down Expand Up @@ -313,6 +318,7 @@ py_test(
srcs = serve_tests_srcs,
tags = ["exclusive", "team:serve"],
deps = [":serve_lib"],
data = [":test_config_files"],
)

py_test(
Expand Down

0 comments on commit 6406cda

Please sign in to comment.