Add `@absltest.skipThisClass` to skip specific classes during testing.

This decorator marks a test in a way that it will be skipped, but none of its subclasses are. Suggested usage is for where you want to share functionality between tests, by having an 'abstract' base class:

```
@absltest.skipThisClass
class _BaseTestCase(absltest.TestCase):
  def test_foo(self):
    self.assertEqual(self.object_under_test.method()

class FooTest(_BaseTestCase):
  def setUp(self):
    self.object_under_test = Foo()

class BarTest(_BaseTestCase):
  def setUp(self):
    self.object_under_test = Bar()
```

There are alternatives, but they have drawbacks:

 * Having `_BaseTestCase` subclass object, and `FooTest` multiple-inherit from both `absltest.TestCase` and `_BaseTestCase`. However, this ends up being problematic for type checking.
 * Repeating the same logic in `absltest.skipThisClass` within `setUpClass` for every class to skip. However, that is repetitive logic that is best put into a utility function.

While `skipThisClass` is similar to `@unittest.skip`, it has an important distinction: regular `skip` will skip the decorated class and all subclasses;
`skipThisClass` only skips the decorated class, allowing base classes to be
correctly skipped while sub-classes are run as tests.

PiperOrigin-RevId: 367965048
Change-Id: Ie050c43c7f2e5dbc5af731171259c27084d1ba12
3 files changed
tree: f0690524abebaeefabe832e52dff2546e730fd6c
  1. absl/
  2. smoke_tests/
  3. third_party/
  4. AUTHORS
  5. CONTRIBUTING.md
  6. LICENSE
  7. MANIFEST.in
  8. README.md
  9. setup.py
  10. WORKSPACE
README.md

Abseil Python Common Libraries

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.

Features

  • Simple application startup
  • Distributed commandline flags system
  • Custom logging module with additional features
  • Testing utilities

Getting Started

Installation

To install the package, simply run:

pip install absl-py

Or install from source:

python setup.py install

Running Tests

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/...

Example Code

Please refer to smoke_tests/sample_app.py as an example to get started.

Documentation

See the Abseil Python Developer Guide.

Future Releases

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.

License

The Abseil Python library is licensed under the terms of the Apache license. See LICENSE for more information.