Add TestCase.enter_context to make it easier to use context managers in tests. When writing tests, re-using the same context manager logic is hard because of the separatation of setUp() from the test being executed. Re-using the logic require decorating the test function (which usually adds an argument to the signature), or copy/pasting the same `with` block (which loses a level of indent and can create a lot of redundant code). This can be particularly annoying with mock.patch, since you must either decorate every function, or add very boilerplate, awkward, and somewhat subtle cleanup logic in setUp to properly patch, start, store, and cleanup the patching and its created mock object. To alleviate this, contextlib.ExitStack can be used to more manually manage the lifecycle of context managers. NOTE: This is a Python 3-only feature because contextlib.ExitStack is Py3-only. While contextlib2 could be used for Py2 support, that involves pulling in another dependency, so can be done in a future change. PiperOrigin-RevId: 277084054 Change-Id: Ic6baee7908a96600ff577217568fec7e5276d48d
This repository is a collection of Python library code for building Python applications. The code is collected from Google's own Python code base, and has been extensively tested and used in production.
To install the package, simply run:
pip install absl-py
Or install from source:
python setup.py install
To run Abseil tests, you can clone the git repo and run bazel:
git clone https://github.com/abseil/abseil-py.git cd abseil-py bazel test absl/...
Please refer to smoke_tests/sample_app.py as an example to get started.
See the Abseil Python Developer Guide.
The current repository includes an initial set of libraries for early adoption. More components and interoperability with Abseil C++ Common Libraries will come in future releases.
The Abseil Python library is licensed under the terms of the Apache license. See LICENSE for more information.