Skip to content

Commit

Permalink
[bazel] Run python unit tests with bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 13, 2019
1 parent 6681d50 commit 7c0c147
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
17 changes: 15 additions & 2 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ py_library(
":get-attribute",
":is-displayed",
],
deps = [
"//third_party/py:urllib3",
],
imports = ["."],
visibility = ["//visibility:public"],
)
Expand All @@ -30,10 +33,20 @@ py_test(
size = "small",
srcs = glob([
"test/unit/**/*.py",
]) + [ "test/run_pytest.py" ],
main = "test/run_pytest.py",
]) + [ "test/runner/run_pytest.py" ],
main = "test/runner/run_pytest.py",
deps = [
":main",
"//third_party/py:pytest",
],
legacy_create_init = False,
)

py_binary(
name = "untar",
visibility = ["//visibility:public"],
srcs = [
"untar.py",
],
legacy_create_init = False,
)
1 change: 1 addition & 0 deletions py/test/run_pytest.py → py/test/runner/run_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with open("pytest.ini", "w") as ini_file:
ini_file.write("[pytest]\n")
ini_file.write("addopts = -r=a\n")
ini_file.write("rootdir = py")
ini_file.write("python_files = test_*.py *_tests.py\n")

raise SystemExit(pytest.main())
30 changes: 30 additions & 0 deletions third_party/py/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
load("//py:defs.bzl", "py_import")

py_import(
name = "py",
wheel = "py-1.4.32-py2.py3-none-any.whl",
)

py_import(
name = "pytest",
wheel = "pytest-3.0.3-py2.py3-none-any.whl",
deps = [
":py",
":pytest-mock",
],
visibility = [
"//visibility:public",
]
)

py_import(
name = "pytest-mock",
wheel = "pytest_mock-1.5.0-py2.py3-none-any.whl",
)

py_import(
name = "urllib3",
wheel = "urllib3-1.23-py2.py3-none-any.whl",
visibility = [
"//visibility:public",
]
)

0 comments on commit 7c0c147

Please sign in to comment.