Skip to content

Commit e160563

Browse files
committed
Add the ability to create python test suites, and use it
This works in much the same way as the test suites for Java do, but with python.
1 parent 66625d7 commit e160563

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

py/BUILD.bazel

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
2-
load("//py:defs.bzl", "pytest_test")
2+
load("//py:defs.bzl", "pytest_test", "py_test_suite")
33
load("//:copy_file.bzl", "copy_file")
44

55
copy_file(
@@ -65,10 +65,9 @@ py_library(
6565
imports = ["."],
6666
)
6767

68-
pytest_test(
68+
py_test_suite(
6969
name = "unit",
7070
size = "small",
71-
python_version = "PY2",
7271
args = [
7372
"-n=auto",
7473
"--instafail",
@@ -97,15 +96,35 @@ py_library(
9796
deps = [],
9897
)
9998

100-
pytest_test(
101-
name = "large-tests",
99+
py_test_suite(
100+
name = "test-chrome",
102101
size = "large",
103102
srcs = glob([
103+
"test/selenium/webdriver/chrome/**/*.py",
104104
"test/selenium/webdriver/common/**/*.py",
105105
"test/selenium/webdriver/support/**/*.py",
106106
]),
107+
args = ["--instafail", "--driver=Chrome"],
108+
tags = [
109+
"no-sandbox",
110+
],
111+
deps = [
112+
":init-tree",
113+
":selenium",
114+
":webserver",
115+
"//third_party/py:pytest",
116+
],
117+
)
118+
119+
py_test_suite(
120+
name = "test-firefox",
121+
size = "large",
122+
srcs = glob([
123+
"test/selenium/webdriver/common/**/*.py",
124+
"test/selenium/webdriver/marionette/**/*.py",
125+
"test/selenium/webdriver/support/**/*.py",
126+
]),
107127
args = ["--instafail", "--driver=Firefox"],
108-
python_version = "PY2",
109128
tags = [
110129
"no-sandbox",
111130
],
@@ -114,5 +133,45 @@ pytest_test(
114133
":selenium",
115134
":webserver",
116135
"//third_party/py:pytest",
117-
]
136+
],
137+
)
138+
139+
py_test_suite(
140+
name = "test-ie",
141+
size = "large",
142+
srcs = glob([
143+
"test/selenium/webdriver/common/**/*.py",
144+
"test/selenium/webdriver/ie/**/*.py",
145+
"test/selenium/webdriver/support/**/*.py",
146+
]),
147+
args = ["--instafail", "--driver=Ie"],
148+
tags = [
149+
"no-sandbox",
150+
],
151+
deps = [
152+
":init-tree",
153+
":selenium",
154+
":webserver",
155+
"//third_party/py:pytest",
156+
],
157+
)
158+
159+
py_test_suite(
160+
name = "test-safari",
161+
size = "large",
162+
srcs = glob([
163+
# "test/selenium/webdriver/common/**/*.py",
164+
"test/selenium/webdriver/safari/**/*.py",
165+
# "test/selenium/webdriver/support/**/*.py",
166+
]),
167+
args = ["--instafail", "--driver=Safari"],
168+
tags = [
169+
"no-sandbox",
170+
],
171+
deps = [
172+
":init-tree",
173+
":selenium",
174+
":webserver",
175+
"//third_party/py:pytest",
176+
],
118177
)

py/defs.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("//py/private:import.bzl", _py_import = "py_import")
22
load("//py/private:pytest.bzl", _pytest_test = "pytest_test")
3+
load("//py/private:suite.bzl", _py_test_suite = "py_test_suite")
34

4-
py_import = _py_import
55
pytest_test = _pytest_test
6+
py_import = _py_import
7+
py_test_suite = _py_test_suite

py/private/suite.bzl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
load("//py/private:pytest.bzl", "pytest_test")
3+
4+
def _is_test(file):
5+
return file.startswith("test_") or file.endswith("_tests.py")
6+
7+
def py_test_suite(name, srcs, size = None, deps = None, python_version = None, imports = None, visibility = None, **kwargs):
8+
library_name = "%s-test-lib" % name
9+
10+
py_library(
11+
name = library_name,
12+
testonly = True,
13+
srcs = srcs,
14+
deps = deps,
15+
imports = imports,
16+
)
17+
18+
tests = []
19+
for src in srcs:
20+
if _is_test(src):
21+
test_name = "%s-%s" % (name, src)
22+
23+
tests.append(test_name)
24+
25+
pytest_test(
26+
name = test_name,
27+
size = size,
28+
srcs = [src],
29+
deps = [library_name],
30+
python_version = python_version,
31+
**kwargs,
32+
)
33+
native.test_suite(
34+
name = name,
35+
tests = tests,
36+
visibility = visibility,
37+
)

0 commit comments

Comments
 (0)