forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py] Lay groundwork for running large tests with python
Turns out we need a custom runner. Implementing this as a macro that generates the runner for us.
- Loading branch information
Showing
10 changed files
with
224 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ java_binary( | |
], | ||
visibility = [ | ||
"//:__pkg__", | ||
"//py:__pkg__", | ||
], | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//py:import.bzl", _py_import = "py_import") | ||
load("//py/private:pytest.bzl", _pytest_test = "pytest_test") | ||
|
||
py_import = _py_import | ||
pytest_test = _pytest_test |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
load("@rules_python//python:defs.bzl", "PyInfo", "PyRuntimeInfo", "py_test") | ||
|
||
def _stringify(paths): | ||
return "[%s]" % (", ".join(["\"%s\"" % path for path in paths])) | ||
|
||
def _pytest_runner_impl(ctx): | ||
if len(ctx.attr.srcs) == 0: | ||
fail("No test files specified.") | ||
|
||
runner = ctx.actions.declare_file(ctx.attr.name) | ||
ctx.actions.write( | ||
runner, | ||
""" | ||
if __name__ == "__main__": | ||
import sys | ||
import pytest | ||
args = sys.argv[1:] + ["-ra", "-s", "--instafail"] + %s + %s | ||
sys.exit(pytest.main(args))""" % (_stringify(ctx.attr.args), _stringify([src.path for src in ctx.files.srcs])), | ||
is_executable = True) | ||
|
||
return [ | ||
DefaultInfo( | ||
files = depset([runner]), | ||
executable = runner, | ||
), | ||
] | ||
|
||
_pytest_runner = rule( | ||
_pytest_runner_impl, | ||
attrs = { | ||
"srcs": attr.label_list( | ||
allow_files = [".py"], | ||
), | ||
"deps": attr.label_list( | ||
providers = [ | ||
PyInfo, | ||
], | ||
), | ||
"args": attr.string_list( | ||
default = [], | ||
), | ||
"python_version": attr.string( | ||
values = ["PY2", "PY3"], | ||
default = "PY3", | ||
), | ||
}, | ||
toolchains = [ | ||
"@rules_python//python:toolchain_type", | ||
] | ||
) | ||
|
||
def pytest_test(name, srcs, deps = None, args = None, python_version = None, **kwargs): | ||
runner_target = "%s-runner.py" % name | ||
|
||
_pytest_runner( | ||
name = runner_target, | ||
testonly = True, | ||
srcs = srcs, | ||
deps = deps, | ||
args = args, | ||
python_version = python_version, | ||
) | ||
|
||
py_test( | ||
name = name, | ||
python_version = python_version, | ||
srcs = srcs + [runner_target], | ||
deps = deps, | ||
main = runner_target, | ||
legacy_create_init = False, | ||
imports = ["."], | ||
**kwargs, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.