From e4f3987f4efa1124b8d58738bde5130d988f181a Mon Sep 17 00:00:00 2001 From: Kevin Ku Date: Wed, 29 Jul 2020 15:53:44 -0700 Subject: [PATCH] Add py_test example. --- BUILD.bazel | 14 ++++++++++++++ README.md | 6 ++++++ main_test.py | 12 ++++++++++++ requirements.txt | 7 +++++++ 4 files changed, 39 insertions(+) create mode 100644 main_test.py diff --git a/BUILD.bazel b/BUILD.bazel index ef18198..f9116b7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -30,6 +30,20 @@ py_binary( python_version = "PY3", ) +py_test( + name = "main_test", + srcs = ["main_test.py"], + deps = [ + requirement("attrs"), + requirement("more-itertools"), + requirement("packaging"), + requirement("pluggy"), + requirement("py"), + requirement("pytest"), + requirement("wcwidth"), + ], +) + #################### # Docker Image #################### diff --git a/README.md b/README.md index f262e41..ee02268 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ Host python version is 3.6.9 Successfully imported psycopg2-binary! ``` +# py_test demo + +``` +bazel test //:main_test +``` + # Docker Image Demo The image we're using is `python3:3.8.3-slim-buster`, which matches the python diff --git a/main_test.py b/main_test.py new file mode 100644 index 0000000..b8cc96d --- /dev/null +++ b/main_test.py @@ -0,0 +1,12 @@ +import platform +import pytest +import sys + +class TestPythonVersion: + def test_version(self): + assert('bazel-out/k8-fastbuild/bin/main_test.runfiles/python_interpreter/python_bin' in sys.executable) + assert(platform.python_version() == "3.8.3") + +if __name__ == "__main__": + import pytest + raise SystemExit(pytest.main([__file__])) diff --git a/requirements.txt b/requirements.txt index 6e2e628..011d5d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,8 @@ +attrs==19.3.0 +more-itertools==8.2.0 +packaging==20.3 +pluggy==0.13.1 psycopg2-binary==2.8.5 +py==1.8.1 +pytest==5.4.1 +wcwidth==0.1.9