Skip to content

Commit

Permalink
Add the ability to create python test suites, and use it
Browse files Browse the repository at this point in the history
This works in much the same way as the test suites for Java do, but
with python.
  • Loading branch information
shs96c committed Nov 11, 2019
1 parent 66625d7 commit e160563
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 8 deletions.
73 changes: 66 additions & 7 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("//py:defs.bzl", "pytest_test")
load("//py:defs.bzl", "pytest_test", "py_test_suite")
load("//:copy_file.bzl", "copy_file")

copy_file(
Expand Down Expand Up @@ -65,10 +65,9 @@ py_library(
imports = ["."],
)

pytest_test(
py_test_suite(
name = "unit",
size = "small",
python_version = "PY2",
args = [
"-n=auto",
"--instafail",
Expand Down Expand Up @@ -97,15 +96,35 @@ py_library(
deps = [],
)

pytest_test(
name = "large-tests",
py_test_suite(
name = "test-chrome",
size = "large",
srcs = glob([
"test/selenium/webdriver/chrome/**/*.py",
"test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/support/**/*.py",
]),
args = ["--instafail", "--driver=Chrome"],
tags = [
"no-sandbox",
],
deps = [
":init-tree",
":selenium",
":webserver",
"//third_party/py:pytest",
],
)

py_test_suite(
name = "test-firefox",
size = "large",
srcs = glob([
"test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/marionette/**/*.py",
"test/selenium/webdriver/support/**/*.py",
]),
args = ["--instafail", "--driver=Firefox"],
python_version = "PY2",
tags = [
"no-sandbox",
],
Expand All @@ -114,5 +133,45 @@ pytest_test(
":selenium",
":webserver",
"//third_party/py:pytest",
]
],
)

py_test_suite(
name = "test-ie",
size = "large",
srcs = glob([
"test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/ie/**/*.py",
"test/selenium/webdriver/support/**/*.py",
]),
args = ["--instafail", "--driver=Ie"],
tags = [
"no-sandbox",
],
deps = [
":init-tree",
":selenium",
":webserver",
"//third_party/py:pytest",
],
)

py_test_suite(
name = "test-safari",
size = "large",
srcs = glob([
# "test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/safari/**/*.py",
# "test/selenium/webdriver/support/**/*.py",
]),
args = ["--instafail", "--driver=Safari"],
tags = [
"no-sandbox",
],
deps = [
":init-tree",
":selenium",
":webserver",
"//third_party/py:pytest",
],
)
4 changes: 3 additions & 1 deletion py/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("//py/private:import.bzl", _py_import = "py_import")
load("//py/private:pytest.bzl", _pytest_test = "pytest_test")
load("//py/private:suite.bzl", _py_test_suite = "py_test_suite")

py_import = _py_import
pytest_test = _pytest_test
py_import = _py_import
py_test_suite = _py_test_suite
37 changes: 37 additions & 0 deletions py/private/suite.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@rules_python//python:defs.bzl", "py_library")
load("//py/private:pytest.bzl", "pytest_test")

def _is_test(file):
return file.startswith("test_") or file.endswith("_tests.py")

def py_test_suite(name, srcs, size = None, deps = None, python_version = None, imports = None, visibility = None, **kwargs):
library_name = "%s-test-lib" % name

py_library(
name = library_name,
testonly = True,
srcs = srcs,
deps = deps,
imports = imports,
)

tests = []
for src in srcs:
if _is_test(src):
test_name = "%s-%s" % (name, src)

tests.append(test_name)

pytest_test(
name = test_name,
size = size,
srcs = [src],
deps = [library_name],
python_version = python_version,
**kwargs,
)
native.test_suite(
name = name,
tests = tests,
visibility = visibility,
)

0 comments on commit e160563

Please sign in to comment.