1616load ("@bazel_binaries//:defs.bzl" , "bazel_binaries" )
1717load (
1818 "@rules_bazel_integration_test//bazel_integration_test:defs.bzl" ,
19- "bazel_integration_tests " ,
19+ "bazel_integration_test " ,
2020 "integration_test_utils" ,
2121)
2222load ("//python:py_test.bzl" , "py_test" )
2323
24+ def _test_runner (* , name , bazel_version , py_main , bzlmod , gazelle_plugin ):
25+ if py_main :
26+ test_runner = "{}_bazel_{}_py_runner" .format (name , bazel_version )
27+ py_test (
28+ name = test_runner ,
29+ srcs = [py_main ],
30+ main = py_main ,
31+ deps = [":runner_lib" ],
32+ # Hide from ... patterns; should only be run as part
33+ # of the bazel integration test
34+ tags = ["manual" ],
35+ )
36+ return test_runner
37+
38+ if bazel_version .startswith ("6" ) and not bzlmod :
39+ if gazelle_plugin :
40+ return "//tests/integration:bazel_6_4_workspace_test_runner_gazelle_plugin"
41+ else :
42+ return "//tests/integration:bazel_6_4_workspace_test_runner"
43+
44+ if bzlmod and gazelle_plugin :
45+ return "//tests/integration:test_runner_gazelle_plugin"
46+ elif bzlmod :
47+ return "//tests/integration:test_runner"
48+ elif gazelle_plugin :
49+ return "//tests/integration:workspace_test_runner_gazelle_plugin"
50+ else :
51+ return "//tests/integration:workspace_test_runner"
52+
2453def rules_python_integration_test (
2554 name ,
2655 workspace_path = None ,
@@ -48,26 +77,6 @@ def rules_python_integration_test(
4877 **kwargs: Passed to the upstream `bazel_integration_tests` rule.
4978 """
5079 workspace_path = workspace_path or name .removesuffix ("_test" )
51- if py_main :
52- test_runner = name + "_py_runner"
53- py_test (
54- name = test_runner ,
55- srcs = [py_main ],
56- main = py_main ,
57- deps = [":runner_lib" ],
58- # Hide from ... patterns; should only be run as part
59- # of the bazel integration test
60- tags = ["manual" ],
61- )
62- elif bzlmod :
63- if gazelle_plugin :
64- test_runner = "//tests/integration:test_runner_gazelle_plugin"
65- else :
66- test_runner = "//tests/integration:test_runner"
67- elif gazelle_plugin :
68- test_runner = "//tests/integration:workspace_test_runner_gazelle_plugin"
69- else :
70- test_runner = "//tests/integration:workspace_test_runner"
7180
7281 # Because glob expansion happens at loading time, the bazel-* symlinks
7382 # in the workspaces can recursively expand to tens-of-thousands of entries,
@@ -89,27 +98,35 @@ def rules_python_integration_test(
8998 ],
9099 )
91100 kwargs .setdefault ("size" , "enormous" )
92- bazel_integration_tests (
93- name = name ,
94- workspace_path = workspace_path ,
95- test_runner = test_runner ,
96- bazel_versions = bazel_versions or bazel_binaries .versions .all ,
97- workspace_files = [name + "_workspace_files" ],
98- # Override the tags so that the `manual` tag isn't applied.
99- tags = (tags or []) + [
100- # These tests are very heavy weight, so much so that only a couple
101- # can be run in parallel without harming their reliability,
102- # overall runtime, and the system's stability. Unfortunately,
103- # there doesn't appear to be a way to tell Bazel to limit their
104- # concurrency, only disable it entirely with exclusive.
105- "exclusive" ,
106- # The default_test_runner() assumes it can write to the user's home
107- # directory for caching purposes. Give it access.
108- "no-sandbox" ,
109- # The CI RBE setup can't successfully run these tests remotely.
110- "no-remote-exec" ,
111- # A special tag is used so CI can run them as a separate job.
112- "integration-test" ,
113- ],
114- ** kwargs
115- )
101+ for bazel_version in bazel_versions or bazel_binaries .versions .all :
102+ test_runner = _test_runner (
103+ name = name ,
104+ bazel_version = bazel_version ,
105+ py_main = py_main ,
106+ bzlmod = bzlmod ,
107+ gazelle_plugin = gazelle_plugin ,
108+ )
109+ bazel_integration_test (
110+ name = "{}_bazel_{}" .format (name , bazel_version ),
111+ workspace_path = workspace_path ,
112+ test_runner = test_runner ,
113+ bazel_version = bazel_version ,
114+ workspace_files = [name + "_workspace_files" ],
115+ # Override the tags so that the `manual` tag isn't applied.
116+ tags = (tags or []) + [
117+ # These tests are very heavy weight, so much so that only a couple
118+ # can be run in parallel without harming their reliability,
119+ # overall runtime, and the system's stability. Unfortunately,
120+ # there doesn't appear to be a way to tell Bazel to limit their
121+ # concurrency, only disable it entirely with exclusive.
122+ "exclusive" ,
123+ # The default_test_runner() assumes it can write to the user's home
124+ # directory for caching purposes. Give it access.
125+ "no-sandbox" ,
126+ # The CI RBE setup can't successfully run these tests remotely.
127+ "no-remote-exec" ,
128+ # A special tag is used so CI can run them as a separate job.
129+ "integration-test" ,
130+ ],
131+ ** kwargs
132+ )
0 commit comments