### Start App After Install Source: https://github.com/bazelbuild/bazel/blob/master/docs/docs/user-manual.mdx Use `bazel mobile-install --start_app` to start the application in a clean state immediately after installation. This is equivalent to using `--start=COLD`. ```bash bazel mobile-install --start_app ``` -------------------------------- ### Install mock with easy_install Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/index.html Install or upgrade the mock library using easy_install. This is an alternative installation method. ```bash easy_install -U mock ``` -------------------------------- ### Build command examples Source: https://github.com/bazelbuild/bazel/blob/master/docs/rules/testing.mdx Illustrates how build flags like '-c opt' and '-c dbg' can affect rule behavior. These commands are for demonstration and not directly part of a test setup. ```shell bazel build //mypkg:real_target -c opt ``` ```shell bazel build //mypkg:real_target -c dbg ``` -------------------------------- ### Add Bazel APT Repository Key and Source Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/ubuntu.mdx This one-time setup step adds the Bazel distribution URI as a package source. It installs necessary packages, downloads the Bazel archive key, and configures the APT sources list. ```bash sudo apt install apt-transport-https curl gnupg -y curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg sudo mv bazel-archive-keyring.gpg /usr/share/keyrings echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list ``` -------------------------------- ### Install Mock with pip or easy_install Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/docs/index.md Install the mock library using pip or easy_install for easy upgrades. ```bash easy_install -U mock ``` ```bash pip install -U mock ``` -------------------------------- ### Run Bazel Binary Installer Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/os-x.mdx Execute the Bazel installer script. The `--user` flag installs Bazel to `$HOME/bin` and sets the `.bazelrc` path to `$HOME/.bazelrc`. Use `--help` for more options. ```bash ./bazel-$BAZEL_VERSION-installer-darwin-x86_64.sh --user ``` -------------------------------- ### Example Repository Structure Source: https://github.com/bazelbuild/bazel/blob/master/docs/rules/deploying.mdx Illustrates a recommended directory layout for a Bazel ruleset, including directories for constraints, runfiles, tests, and examples. ```plaintext / LICENSE README MODULE.bazel mockascript/ constraints/ BUILD runfiles/ BUILD runfiles.mocs BUILD defs.bzl tests/ BUILD some_test.sh another_test.py examples/ BUILD bin.mocs lib.mocs test.mocs ``` -------------------------------- ### Install mock with pip Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/index.html Install or upgrade the mock library using pip. This is the recommended method for most users. ```bash pip install -U mock ``` -------------------------------- ### Run Bazel Binary Installer Source: https://github.com/bazelbuild/bazel/blob/master/site/en/install/ubuntu.md Makes the downloaded Bazel binary installer script executable and then runs it with the --user flag to install Bazel in the user's home directory. ```bash chmod +x bazel-{{ '' }}version{{ '' }}-installer-linux-x86_64.sh ./bazel-{{ '' }}version{{ '' }}-installer-linux-x86_64.sh --user ``` -------------------------------- ### Run Bazel Binary Installer Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/ubuntu.mdx Executes the Bazel binary installer script. The `--user` flag installs Bazel to `$HOME/bin` and sets the `.bazelrc` path to `$HOME/.bazelrc`, suitable for users without admin permissions. ```bash chmod +x bazel-version-installer-linux-x86_64.sh ./bazel-version-installer-linux-x86_64.sh --user ``` -------------------------------- ### Clone Sample Project Source: https://github.com/bazelbuild/bazel/blob/master/docs/query/quickstart.mdx Retrieve the sample application from Bazel's Examples repository to use for this tutorial. ```bash git clone https://github.com/bazelbuild/examples.git ``` -------------------------------- ### Dockerfile to Install Tool Package Source: https://github.com/bazelbuild/bazel/blob/master/docs/remote/ci.mdx Example Dockerfile snippet to install a specific tool package within the rbe-ubuntu16-04 container. ```dockerfile FROM gcr.io/cloud-marketplace/google/rbe-ubuntu16-04@sha256:sha256-checksum RUN apt-get update && yes | apt-get install -y my_tool_package ``` -------------------------------- ### Create Action with Arguments and Inputs Source: https://github.com/bazelbuild/bazel/blob/master/docs/extending/rules.mdx This example demonstrates creating a `run` action. It uses `ctx.actions.args` to efficiently build the argument list, including transitive headers and source files, and specifies inputs and outputs. ```python def _example_library_impl(ctx): ... transitive_headers = [dep[ExampleInfo].headers for dep in ctx.attr.deps] headers = depset(ctx.files.hdrs, transitive = transitive_headers) srcs = ctx.files.srcs inputs = depset(srcs, transitive = [headers]) output_file = ctx.actions.declare_file(ctx.label.name + ".output") args = ctx.actions.args() args.add_joined("-h", headers, join_with=",") args.add_joined("-s", srcs, join_with=",") args.add("-o", output_file) ctx.actions.run( mnemonic = "ExampleCompile", executable = ctx.executable._compiler, arguments = [args], inputs = inputs, outputs = [output_file], ) ... ``` -------------------------------- ### Install Specific Bazel Version on openSUSE Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/suse.mdx To install a particular version of Bazel, specify the version number in the package name. For example, to install Bazel 4.2, use the command below. Root privileges are required. ```posix-terminal zypper install bazel4.2 ``` -------------------------------- ### Example .bazelrc Configuration Source: https://github.com/bazelbuild/bazel/blob/master/docs/run/bazelrc.mdx This example demonstrates how to set startup options, import other rc files, define build and query options, and create a custom configuration named 'memcheck'. ```bazelrc # Bob's Bazel option defaults startup --host_jvm_args=-XX:-UseParallelGC import /home/bobs_project/bazelrc build --show_timestamps --keep_going --jobs 600 build --color=yes query --keep_going # Definition of --config=memcheck build:memcheck --strip=never --test_timeout=3600 ``` -------------------------------- ### Dockerfile to Install Package Source: https://github.com/bazelbuild/bazel/blob/master/site/en/remote/ci.md Example Dockerfile snippet to install a package within the rbe-ubuntu16-04 container. Ensure the base image SHA256 checksum is up-to-date. ```dockerfile FROM gcr.io/cloud-marketplace/google/rbe-ubuntu16-04@sha256:{{ '' }}sha256-checksum{{ '' }} RUN apt-get update && yes | apt-get install -y {{ '' }}my_tool_package{{ '' }} ``` -------------------------------- ### Run the Built Binary Source: https://github.com/bazelbuild/bazel/blob/master/docs/start/cpp.mdx Execute the compiled 'hello-world' program to see the output. ```posix-terminal bazel-bin/main/hello-world ``` -------------------------------- ### Start and Stop Patches Manually Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/docs/patch.md Use start() and stop() methods on patcher objects for manual control over patches, useful for complex setup or multiple patches without decorators. The mock object is returned by start() if patch creates one. ```python from unittest.mock import patch my_patcher = patch('module.ClassName') # Start the patch mock_object = my_patcher.start() # ... use the mock ... # Stop the patch my_patcher.stop() ``` -------------------------------- ### HTTP GET Request for Action Cache Metadata Source: https://github.com/bazelbuild/bazel/blob/master/docs/remote/caching.mdx Example of a Bazel GET request to download action cache metadata from a remote cache server. The request targets the '/ac/' path with the action's SHA256 hash. ```http GET /cache/ac/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b HTTP/1.1 Host: localhost:8080 Accept: */* Connection: Keep-Alive ``` -------------------------------- ### Skyfocus Example with Stats and Active Directories Source: https://github.com/bazelbuild/bazel/blob/master/docs/advanced/performance/memory.mdx This example demonstrates enabling Skyfocus, specifying active directories, and requesting post-garbage collection memory statistics. It shows how Skyfocus can significantly reduce memory usage while maintaining build performance. ```sh bazel test //pkg:target //tests/... --experimental_enable_skyfocus --experimental_active_directories=dir1,dir2,dir3/subdir --experimental_skyfocus_dump_post_gc_stats ``` ```none INFO: --experimental_enable_skyfocus is enabled. Blaze will reclaim memory not needed to build the working set. Run 'blaze dump --skyframe=working_set' to show the working set, after this command. WARNING: Changes outside of the working set will cause a build error. INFO: Analyzed 149 targets (4533 packages loaded, 169438 targets configured). INFO: Found 25 targets and 124 test targets... INFO: Updated working set successfully. INFO: Focusing on 334 roots, 3 leafs... (use --experimental_skyfocus_dump_keys to show them) INFO: Heap: 1237MB -> 676MB (-45.31%) INFO: Elapsed time: 192.670s ... INFO: Build completed successfully, 62303 total actions ``` -------------------------------- ### Managing Patches with setUp and tearDown in Python Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/_sources/examples.txt Use patcher.start() in setUp and patcher.stop() in tearDown to manage patches. Ensure stop() is called, even if exceptions occur, by using addCleanup. ```python class MyTest(TestCase): def setUp(self): self.patcher = patch('mymodule.foo') self.mock_foo = self.patcher.start() def test_foo(self): self.assertTrue(mymodule.foo is self.mock_foo) def tearDown(self): self.patcher.stop() MyTest('test_foo').run() ``` ```python class MyTest(TestCase): def setUp(self): patcher = patch('mymodule.foo') self.addCleanup(patcher.stop) self.mock_foo = patcher.start() def test_foo(self): self.assertTrue(mymodule.foo is self.mock_foo) MyTest('test_foo').run() ``` -------------------------------- ### Nest patches using start and stop methods Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/docs/examples.md Avoid deep indentation from nested 'with' statements when applying multiple patches. This example utilizes the start and stop methods of patch objects, along with a helper function, to manage patches more cleanly. ```python from mock import patch def create_patch(target): patcher = patch(target) mock = patcher.start() mock.patcher = patcher return mock with self.context_manager_for_patching(): mock_os = create_patch('os') mock_sys = create_patch('sys') # Use mocks here mock_sys.patcher.stop() mock_os.patcher.stop() ``` -------------------------------- ### Build Targets Relative to Current Directory Source: https://github.com/bazelbuild/bazel/blob/master/docs/run/build.mdx Target patterns not starting with `//` are resolved relative to the current working directory. For example, if the working directory is `foo`. ```bash bazel build :foo ``` ```bash bazel build bar:wiz ``` ```bash bazel build bar/wiz ``` ```bash bazel build bar:all ``` ```bash bazel build :all ``` ```bash bazel build ...:all ``` ```bash bazel build ... ``` ```bash bazel build bar/...:all ``` -------------------------------- ### Build C++ hello-world example Source: https://github.com/bazelbuild/bazel/blob/master/docs/configure/windows.mdx Build a simple C++ hello-world target using Bazel. This command assumes Bazel is in your PATH and the example project is available. ```bash bazel build //examples/cpp:hello-world ``` ```bash bazel-bin/examples/cpp/hello-world.exe ``` -------------------------------- ### Working-Directory Relative Patterns Source: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/runtime/commands/target-syntax.txt Patterns not starting with '//' are relative to the current working directory. For example, if cwd is 'workspace/foo', then 'bar:wiz' is equivalent to '//foo/bar:wiz'. ```bazel ...:all ``` ```bazel ... ``` ```bazel bar/...:all ``` ```bazel bar/... ``` ```bazel bar:wiz ``` ```bazel :foo ``` ```bazel bar ``` ```bazel foo/bar ``` ```bazel bar:all ``` ```bazel :all ``` -------------------------------- ### Bazel Command Line Example Source: https://github.com/bazelbuild/bazel/blob/master/docs/contribute/codebase.mdx Illustrates the distinction between startup options (affecting the server) and command options (affecting a single command). Startup options precede the command name, while command options follow. ```bash bazel --host_jvm_args=-Xmx8G build -c opt //foo:bar ``` -------------------------------- ### Debug App After Install Source: https://github.com/bazelbuild/bazel/blob/master/docs/docs/user-manual.mdx Use `bazel mobile-install --debug_app` to wait for a debugger to attach before starting the application in a clean state. This is equivalent to using `--start=DEBUG`. ```bash bazel mobile-install --debug_app ``` -------------------------------- ### Build and Run C++ Hello World Example Source: https://github.com/bazelbuild/bazel/blob/master/site/en/configure/windows.md Commands to build a C++ 'hello-world' target using Bazel and then execute the compiled binary. By default, binaries target the x64 architecture. ```terminal bazel build //examples/cpp:hello-world ``` ```terminal bazel-bin\examples\cpp\hello-world.exe ``` -------------------------------- ### Go test example Source: https://github.com/bazelbuild/bazel/blob/master/docs/start/go.mdx This Go test file checks if the `Get` function returns a valid message from a predefined list. It requires compilation within the same Go package as the `fortune.go` file. ```go package fortune import ( "slices" "testing" ) // TestGet checks that Get returns one of the strings from fortunes. func TestGet(t *testing.T) { msg := Get() if i := slices.Index(fortunes, msg); i < 0 { t.Errorf("Get returned %q, not one the expected messages", msg) } } ``` -------------------------------- ### Get Bazel Version Information Source: https://github.com/bazelbuild/bazel/blob/master/docs/docs/user-manual.mdx The `bazel --version` command outputs version details, including changelist and build date, without starting the Bazel server. It does not require a workspace directory. ```bash bazel --version ``` -------------------------------- ### Build command examples Source: https://github.com/bazelbuild/bazel/blob/master/site/en/rules/testing.md These commands demonstrate building a target with different compilation modes. ```shell bazel build //mypkg:real_target -c opt ``` ```shell bazel build //mypkg:real_target -c dbg ``` -------------------------------- ### Bazel BUILD File Example Source: https://github.com/bazelbuild/bazel/blob/master/docs/extending/aspects.mdx Example BUILD file demonstrating the usage of `cc_library`, `cc_binary`, and the custom `file_count_rule` with specific extensions. ```python load('//:file_count.bzl', 'file_count_rule') cc_library( name = 'lib', srcs = [ 'lib.h', 'lib.cc', ], ) cc_binary( name = 'app', srcs = [ 'app.h', 'app.cc', 'main.cc', ], deps = ['lib'], ) file_count_rule( name = 'file_count', deps = ['app'], extension = 'h', ) ``` -------------------------------- ### Define a module extension with tag classes Source: https://github.com/bazelbuild/bazel/blob/master/docs/external/extension.mdx Define a module extension using `module_extension`, specifying tag classes with their attributes. This example shows the definition for the 'maven' extension with 'install' and 'artifact' tag classes. ```python # @rules_jvm_external//:extensions.bzl _install = tag_class(attrs = {"artifacts": attr.string_list(), ...}) _artifact = tag_class(attrs = {"group": attr.string(), "artifact": attr.string(), ...}) maven = module_extension( implementation = _maven_impl, tag_classes = {"install": _install, "artifact": _artifact}, ) ``` -------------------------------- ### Specify tags for a module extension Source: https://github.com/bazelbuild/bazel/blob/master/docs/external/extension.mdx After bringing an extension into scope, use dot-syntax to specify tags according to the extension's tag classes. This example adds 'install' and 'artifact' tags for the 'maven' extension. ```python maven.install(artifacts = ["org.junit:junit:4.13.2"]) maven.artifact(group = "com.google.guava", artifact = "guava", version = "27.0-jre", exclusions = ["com.google.j2objc:j2objc-annotations"]) ``` -------------------------------- ### Boolean select() Fails Silently in Macros Source: https://github.com/bazelbuild/bazel/blob/master/site/en/configure/attributes.md When a select() statement returns a boolean within a macro, it can fail silently because the macro evaluates the select() object itself, which defaults to true. This example demonstrates the setup and Bazel output. ```sh $cat myapp/defs.bzl def my_boolean_macro(boolval): print("TRUE" if boolval else "FALSE") $cat myapp/BUILD load("//myapp:defs.bzl", "my_boolean_macro") my_boolean_macro( boolval = select({ "//third_party/bazel_platforms/cpu:x86_32": True, "//third_party/bazel_platforms/cpu:ppc": False, }), ) $ bazel build //myapp:all --cpu=x86 DEBUG: /myworkspace/myapp/defs.bzl:4:3: TRUE. $ bazel build //mypro:all --cpu=ppc DEBUG: /myworkspace/myapp/defs.bzl:4:3: TRUE. ``` -------------------------------- ### Using patch start/stop in setUp and tearDown Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/examples.html Manage patches manually using patcher.start() in setUp and patcher.stop() in tearDown. Ensure stop() is called to undo the patching, even if exceptions occur. ```python class MyTest(TestCase): def setUp(self): self.patcher = patch('mymodule.foo') self.mock_foo = self.patcher.start() def test_foo(self): self.assertTrue(mymodule.foo is self.mock_foo) def tearDown(self): self.patcher.stop() ``` -------------------------------- ### Run Tests with setup.py Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/docs/index.txt If setuptools and unittest2 are installed, you can run the test suite using 'python setup.py test'. ```bash python setup.py test ``` -------------------------------- ### Managing Patches with setUp and tearDown Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/docs/examples.txt Use patcher.start() in setUp and patcher.stop() in tearDown to manage patches. Ensure stop() is called to undo the patching, even if exceptions occur. ```python class MyTest(TestCase): def setUp(self): self.patcher = patch('mymodule.foo') self.mock_foo = self.patcher.start() def test_foo(self): self.assertTrue(mymodule.foo is self.mock_foo) def tearDown(self): self.patcher.stop() MyTest('test_foo').run() ``` -------------------------------- ### Enable Verbose Docker Sandbox Errors Source: https://github.com/bazelbuild/bazel/blob/master/site/en/remote/sandbox.md If you encounter errors related to the Docker spawn strategy, use the `--experimental_docker_verbose` flag to get more detailed error messages. This can help diagnose issues with your Docker setup or user permissions. ```bash bazel build --config=docker-sandbox --experimental_docker_verbose {{ '' }}target{{ '' }} ``` -------------------------------- ### Enable Verbose Docker Sandbox Errors Source: https://github.com/bazelbuild/bazel/blob/master/docs/remote/sandbox.mdx If you encounter 'docker' is an invalid value for docker spawn strategy, run the build again with the `--experimental_docker_verbose` flag to get more detailed error messages. This often indicates a Docker installation issue or permission problems. ```none ERROR: 'docker' is an invalid value for docker spawn strategy. ``` -------------------------------- ### Explain Build Steps Source: https://github.com/bazelbuild/bazel/blob/master/docs/docs/user-manual.mdx Use `--explain` with a filename to log detailed explanations for each build step, helping to diagnose unexpected rebuilds. This option may incur a small performance penalty. ```bash % bazel build --explain=explain.log //myproject:all ``` -------------------------------- ### Install Bazel via Homebrew Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/os-x.mdx After installing Homebrew, use this command to install the Bazel package. This is a straightforward method for managing Bazel installations. ```bash brew install bazel ``` -------------------------------- ### Install Required Packages for Binary Installer Source: https://github.com/bazelbuild/bazel/blob/master/site/en/install/ubuntu.md Installs essential packages like a C++ compiler, unzip, and zip, which are necessary for Bazel to function when using the binary installer. Also includes installing a JDK for Java builds. ```bash sudo apt install g++ unzip zip ``` ```bash sudo apt-get install default-jdk ``` -------------------------------- ### Install Bazel using Scoop Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/windows.mdx Install the Bazel package using the Scoop package manager after Scoop has been installed. This command installs the latest available version of Bazel. ```bash scoop install bazel ``` -------------------------------- ### Install Required Packages for Binary Installer Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/ubuntu.mdx Installs essential packages for the Bazel binary installer to function correctly on Ubuntu. This includes a C++ compiler and utilities for handling zip archives. ```bash sudo apt install g++ unzip zip ``` -------------------------------- ### Apply Transition to Multi-Value Build Setting Source: https://github.com/bazelbuild/bazel/blob/master/docs/extending/config.mdx When transitioning a multi-value build setting, the value must be provided as a list. This example sets the `//example:roasts` build setting to `["dark"]`. ```python # example/transitions/rules.bzl def _transition_impl(settings, attr): # Using a value of just "dark" here will throw an error return {"//example:roasts" : ["dark"]}, coffee_transition = transition( implementation = _transition_impl, inputs = [], outputs = ["//example:roasts"] ) ``` -------------------------------- ### Install Android App with Bazel Mobile Install Source: https://github.com/bazelbuild/bazel/blob/master/docs/docs/mobile-install.mdx Use this command to install or update an Android app on a connected device. App startup may be slightly slower after the first installation. ```bash bazel mobile-install :your_target ``` -------------------------------- ### BUILD File Structure Example Source: https://github.com/bazelbuild/bazel/blob/master/docs/build/style-guide.mdx Illustrates the recommended order for elements in a BUILD file, including standalone comments, load statements, package function, and rule calls. Note the use of an empty line after standalone comments. ```python # Standalone comment (such as to make a section in a file) # Comment for the cc_library below cc_library(name = "cc") ``` -------------------------------- ### Manual Patching with start() and stop() Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/patch.html Use start() to apply a patch and stop() to undo it. The mock object is returned by start(). ```python patcher = patch('package.module.ClassName') from package import module original = module.ClassName new_mock = patcher.start() assert module.ClassName is not original assert module.ClassName is new_mock patcher.stop() assert module.ClassName is original assert module.ClassName is not new_mock ``` -------------------------------- ### Install Bazel Prerequisites on Ubuntu Linux Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/compile-source.mdx Install the necessary build tools, JDK, Python, and archive utilities on Ubuntu Linux using apt-get. ```bash sudo apt-get install build-essential openjdk-21-jdk python3 zip unzip ``` -------------------------------- ### Verify Bazel Installation (Homebrew) Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/os-x.mdx Run this command to confirm that Bazel has been successfully installed via Homebrew and to check the installed version. ```bash bazel --version ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/bazelbuild/bazel/blob/master/docs/install/os-x.mdx Use this command to install Homebrew, a package manager for macOS, which is a prerequisite for installing Bazel via Homebrew. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Transition on Native Build Option Source: https://github.com/bazelbuild/bazel/blob/master/docs/extending/config.mdx Declare reads and writes on native build configuration options using a special prefix. This example transitions the `--cpu` option. ```python # example/transitions/transitions.bzl def _impl(settings, attr): _ignore = (settings, attr) return {"//command_line_option:cpu": "k8"} cpu_transition = transition( implementation = _impl, inputs = [], outputs = ["//command_line_option:cpu"] ) ``` -------------------------------- ### Example BUILD file Source: https://github.com/bazelbuild/bazel/blob/master/site/en/extending/aspects.md Defines a dependency graph for Java libraries. Used to illustrate Bazel's analysis of dependency graphs. ```python java_library(name = 'W', ...) java_library(name = 'Y', deps = [':W'], ...) java_library(name = 'Z', deps = [':W'], ...) java_library(name = 'Q', ...) java_library(name = 'T', deps = [':Q'], ...) java_library(name = 'X', deps = [':Y',':Z'], runtime_deps = [':T'], ...) ``` -------------------------------- ### Patching in setUp and tearDown Methods Source: https://github.com/bazelbuild/bazel/blob/master/third_party/py/mock/html/patch.html Manage multiple patches within a TestCase's setUp and tearDown methods for setup and cleanup. ```python class MyTest(TestCase): def setUp(self): self.patcher1 = patch('package.module.Class1') self.patcher2 = patch('package.module.Class2') self.MockClass1 = self.patcher1.start() self.MockClass2 = self.patcher2.start() def tearDown(self): self.patcher1.stop() self.patcher2.stop() def test_something(self): assert package.module.Class1 is self.MockClass1 assert package.module.Class2 is self.MockClass2 ```