--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/a1f3277d-c5b4-4e98-841c-68f8dcfb9a62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
.
|____.env
|____env.sample
|____heartbeat
| |______init__.py
| |____heartbeat.py
| |____heartbeat.pyc
| |____tests
| | |______init__.py
| | |____unit
| | | |______init__.py
| | | |____bogus_test.py
| | | |____heartbeat_test.py
|____kubernetes
| |____configmap.yaml
| |____deployment.yaml
|____Makefile
|____README.md
|____requirements.txt
|____WORKSPACE
I added the following to my BUILD file:
SOURCES = glob(["heartbeat/*.py"])
UNIT_TESTS = glob(["heartbeat/tests/unit/*test.py"])
[
py_test(
name=src[:-3],
deps=all_requirements,
srcs=SOURCES + [src],
) for src in UNIT_TESTS
]
do
bazel test //:${i%.py} --cache_test_results=no
done
Each *_test rule defines a single executable file, so you will need a separate rule for each file with a main in it. However, you can do that automatically via list comprehensions and glob. Something like this (untested):[py_test(name = src[:-3],srcs = [src,],) for src in glob(['*_test.py'])]And then to test all of them at once, you can use a target wildcard like `bazel test //unit_tests/...`.
On Thu, Mar 1, 2018 at 12:09 PM, Charlie White <cha...@gmail.com> wrote:
After much trial and error and community support, I have been able to build a Docker image with Python source that includes multiple packages. I am now trying to figure out tests. I have defined a set of tests that I have previously executed with pytest. I have created a unit_test target using the py_test rule and it generates an entire standalone python script app that executes that single unit test file as defined by "main" in the rule. What I would like to do is run all *_test.py files that are in my unit_tests directory. I typically break my tests into small pieces that test only one segment of the application in each. I rely on pytest to find all the test files, and execute all the defined tests cases. How do I accomplish this with Bazel?I apologize if this question has already been asked and answered, or if there is documentation somewhere that better defines how to use py_test.Thanks
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/6d2b4162-d40d-4305-8446-535b81620e95%40googlegroups.com.