# tf.test.TestCase

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2398-L3773) |

Base class for tests that need to test TensorFlow.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.test.TestCase`](https://www.tensorflow.org/api_docs/python/tf/test/TestCase)

<br />

    tf.test.TestCase(
        methodName='runTest'
    )

## Child Classes

[`class failureException`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/test/TestCase/failureException)

## Methods

### `addClassCleanup`

    @classmethod
    addClassCleanup(
        function, *args, /, **kwargs
    )

Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).

### `addCleanup`

    addCleanup(
        function, *args, /, **kwargs
    )

Add a function, with arguments, to be called when the test is completed.
Functions added are called on a LIFO basis and are
called after tearDown on test failure or success.

Cleanup items are called even if setUp fails (unlike tearDown).

### `addTypeEqualityFunc`

    addTypeEqualityFunc(
        typeobj, function
    )

Add a type specific assertEqual style function to compare a type.

This method is for use by TestCase subclasses that need to register
their own type equality functions to provide nicer error messages.

<br />

<br />

<br />

| Args ||
|---|---|
| `typeobj` | The data type to call this function on when both values are of the same type in assertEqual(). |
| `function` | The callable taking two arguments and an optional msg= argument that raises self.failureException with a useful error message when the two arguments are not equal. |

<br />

### `assertAllClose`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3139-L3170)

    assertAllClose(
        a, b, rtol=1e-06, atol=1e-06, msg=None
    )

Asserts that two structures of numpy arrays or Tensors, have near values.

`a` and `b` can be arbitrarily nested structures. A layer of a nested
structure can be a `dict`, `namedtuple`, `tuple` or `list`.

> [!NOTE]
> **Note:** the implementation follows [`numpy.allclose`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.allclose.html) (and numpy.testing.assert_allclose). It checks whether two arrays are element-wise equal within a tolerance. The relative difference (`rtol * abs(b)`) and the absolute difference `atol` are added together to compare against the absolute difference between `a` and `b`.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The expected numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these. |
| `b` | The actual numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these. |
| `rtol` | relative tolerance. |
| `atol` | absolute tolerance. |
| `msg` | Optional message to report on failure. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | if only one of `a[p]` and `b[p]` is a dict or `a[p]` and `b[p]` have different length, where `[p]` denotes a path to the nested structure, e.g. given `a = [(1, 1), {'d': (6, 7)}]` and `[p] = [1]['d']`, then `a[p] = (6, 7)`. |

<br />

### `assertAllCloseAccordingToType`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3172-L3219)

    assertAllCloseAccordingToType(
        a,
        b,
        rtol=1e-06,
        atol=1e-06,
        float_rtol=1e-06,
        float_atol=1e-06,
        half_rtol=0.001,
        half_atol=0.001,
        bfloat16_rtol=0.01,
        bfloat16_atol=0.01,
        msg=None
    )

Like assertAllClose, but also suitable for comparing fp16 arrays.

In particular, the tolerance is reduced to 1e-3 if at least
one of the arguments is of type float16.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | the expected numpy ndarray or anything can be converted to one. |
| `b` | the actual numpy ndarray or anything can be converted to one. |
| `rtol` | relative tolerance. |
| `atol` | absolute tolerance. |
| `float_rtol` | relative tolerance for float32. |
| `float_atol` | absolute tolerance for float32. |
| `half_rtol` | relative tolerance for float16. |
| `half_atol` | absolute tolerance for float16. |
| `bfloat16_rtol` | relative tolerance for bfloat16. |
| `bfloat16_atol` | absolute tolerance for bfloat16. |
| `msg` | Optional message to report on failure. |

<br />

### `assertAllEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3246-L3304)

    assertAllEqual(
        a, b, msg=None
    )

Asserts that two numpy arrays or Tensors have the same values.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | the expected numpy ndarray or anything can be converted to one. |
| `b` | the actual numpy ndarray or anything can be converted to one. |
| `msg` | Optional message to report on failure. |

<br />

### `assertAllGreater`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3322-L3333)

    assertAllGreater(
        a, comparison_target
    )

Assert element values are all greater than a target value.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `comparison_target` | The target value of comparison. |

<br />

### `assertAllGreaterEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3348-L3359)

    assertAllGreaterEqual(
        a, comparison_target
    )

Assert element values are all greater than or equal to a target value.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `comparison_target` | The target value of comparison. |

<br />

### `assertAllInRange`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3407-L3464)

    assertAllInRange(
        target,
        lower_bound,
        upper_bound,
        open_lower_bound=False,
        open_upper_bound=False
    )

Assert that elements in a Tensor are all in a given range.

<br />

<br />

<br />

| Args ||
|---|---|
| `target` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `lower_bound` | lower bound of the range |
| `upper_bound` | upper bound of the range |
| `open_lower_bound` | (`bool`) whether the lower bound is open (i.e., \> rather than the default \>=) |
| `open_upper_bound` | (`bool`) whether the upper bound is open (i.e., \< rather than the default \<=) |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `AssertionError` | if the value tensor does not have an ordered numeric type (float\* or int\*), or if there are nan values, or if any of the elements do not fall in the specified range. |

<br />

### `assertAllInSet`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3466-L3486)

    assertAllInSet(
        target, expected_set
    )

Assert that elements of a Tensor are all in a given closed set.

<br />

<br />

<br />

| Args ||
|---|---|
| `target` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `expected_set` | (`list`, `tuple` or `set`) The closed set that the elements of the value of `target` are expected to fall into. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `AssertionError` | if any of the elements do not fall into `expected_set`. |

<br />

### `assertAllLess`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3335-L3346)

    assertAllLess(
        a, comparison_target
    )

Assert element values are all less than a target value.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `comparison_target` | The target value of comparison. |

<br />

### `assertAllLessEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3361-L3372)

    assertAllLessEqual(
        a, comparison_target
    )

Assert element values are all less than or equal to a target value.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `comparison_target` | The target value of comparison. |

<br />

### `assertAlmostEqual`

    assertAlmostEqual(
        first, second, places=None, msg=None, delta=None
    )

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most significant digit).

If the two objects compare equal then they will automatically
compare almost equal.

### `assertAlmostEquals`

    assertAlmostEquals(
        *args, **kwargs
    )

### `assertArrayNear`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2945-L2960)

    assertArrayNear(
        farray1, farray2, err, msg=None
    )

Asserts that two float arrays are near each other.

Checks that for all elements of farray1 and farray2
\|f1 - f2\| \< err. Asserts a test failure if not.

<br />

<br />

<br />

| Args ||
|---|---|
| `farray1` | a list of float values. |
| `farray2` | a list of float values. |
| `err` | a float value. |
| `msg` | Optional message to report on failure. |

<br />

### `assertBetween`

    assertBetween(
        value, minv, maxv, msg=None
    )

Asserts that value is between minv and maxv (inclusive).

### `assertCommandFails`

    assertCommandFails(
        command, regexes, env=None, close_fds=True, msg=None
    )

Asserts a shell command fails and the error matches a regex in a list.

<br />

<br />

<br />

| Args ||
|---|---|
| `command` | List or string representing the command to run. |
| `regexes` | the list of regular expression strings. |
| `env` | Dictionary of environment variable settings. If None, no environment variables will be set for the child process. This is to make tests more hermetic. NOTE: this behavior is different than the standard subprocess module. |
| `close_fds` | Whether or not to close all open fd's in the child after forking. |
| `msg` | Optional message to report on failure. |

<br />

### `assertCommandSucceeds`

    assertCommandSucceeds(
        command, regexes=(b'',), env=None, close_fds=True, msg=None
    )

Asserts that a shell command succeeds (i.e. exits with code 0).

<br />

<br />

<br />

| Args ||
|---|---|
| `command` | List or string representing the command to run. |
| `regexes` | List of regular expression byte strings that match success. |
| `env` | Dictionary of environment variable settings. If None, no environment variables will be set for the child process. This is to make tests more hermetic. NOTE: this behavior is different than the standard subprocess module. |
| `close_fds` | Whether or not to close all open fd's in the child after forking. |
| `msg` | Optional message to report on failure. |

<br />

### `assertContainsExactSubsequence`

    assertContainsExactSubsequence(
        container, subsequence, msg=None
    )

Asserts that "container" contains "subsequence" as an exact subsequence.

Asserts that "container" contains all the elements of "subsequence", in
order, and without other elements interspersed. For example, \[1, 2, 3\] is an
exact subsequence of \[0, 0, 1, 2, 3, 0\] but not of \[0, 0, 1, 2, 0, 3, 0\].

<br />

<br />

<br />

| Args ||
|---|---|
| `container` | the list we're testing for subsequence inclusion. |
| `subsequence` | the list we hope will be an exact subsequence of container. |
| `msg` | Optional message to report on failure. |

<br />

### `assertContainsInOrder`

    assertContainsInOrder(
        strings, target, msg=None
    )

Asserts that the strings provided are found in the target in order.

This may be useful for checking HTML output.

<br />

<br />

<br />

| Args ||
|---|---|
| `strings` | A list of strings, such as \[ 'fox', 'dog' \] |
| `target` | A target string in which to look for the strings, such as 'The quick brown fox jumped over the lazy dog'. |
| `msg` | Optional message to report on failure. |

<br />

### `assertContainsSubsequence`

    assertContainsSubsequence(
        container, subsequence, msg=None
    )

Asserts that "container" contains "subsequence" as a subsequence.

Asserts that "container" contains all the elements of "subsequence", in
order, but possibly with other elements interspersed. For example, \[1, 2, 3\]
is a subsequence of \[0, 0, 1, 2, 0, 3, 0\] but not of \[0, 0, 1, 3, 0, 2, 0\].

<br />

<br />

<br />

| Args ||
|---|---|
| `container` | the list we're testing for subsequence inclusion. |
| `subsequence` | the list we hope will be a subsequence of container. |
| `msg` | Optional message to report on failure. |

<br />

### `assertContainsSubset`

    assertContainsSubset(
        expected_subset, actual_set, msg=None
    )

Checks whether actual iterable is a superset of expected iterable.

### `assertCountEqual`

    assertCountEqual(
        first, second, msg=None
    )

Asserts that two iterables have the same elements, the same number of times, without regard to order.

    self.assertEqual(Counter(list(first)),
                     Counter(list(second)))

Example:

    - [0, 1, 1] and [1, 0, 1] compare equal.
    - [0, 0, 1] and [0, 1] compare unequal.

### `assertDTypeEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3488-L3501)

    assertDTypeEqual(
        target, expected_dtype
    )

Assert ndarray data type is equal to expected.

<br />

<br />

<br />

| Args ||
|---|---|
| `target` | The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). |
| `expected_dtype` | Expected data type. |

<br />

### `assertDeviceEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3585-L3597)

    assertDeviceEqual(
        device1, device2, msg=None
    )

Asserts that the two given devices are the same.

<br />

<br />

<br />

| Args ||
|---|---|
| `device1` | A string device name or TensorFlow `DeviceSpec` object. |
| `device2` | A string device name or TensorFlow `DeviceSpec` object. |
| `msg` | Optional message to report on failure. |

<br />

### `assertDictContainsSubset`

    assertDictContainsSubset(
        subset, dictionary, msg=None
    )

Checks whether dictionary is a superset of subset.

### `assertDictEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3599-L3623)

    assertDictEqual(
        a, b, msg=None
    )

Assert that two given dictionary of tensors are the same.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | Expected dictionary with numpy ndarray or anything else that can be converted to one as values. |
| `b` | Actual dictionary with numpy ndarray or anything else that can be converted to one as values. |
| `msg` | Optional message to report on failure. |

<br />

### `assertEmpty`

    assertEmpty(
        container, msg=None
    )

Asserts that an object has zero length.

<br />

<br />

<br />

| Args ||
|---|---|
| `container` | Anything that implements the collections.abc.Sized interface. |
| `msg` | Optional message to report on failure. |

<br />

### `assertEndsWith`

    assertEndsWith(
        actual, expected_end, msg=None
    )

Asserts that actual.endswith(expected_end) is True.

<br />

<br />

<br />

| Args ||
|---|---|
| `actual` | str |
| `expected_end` | str |
| `msg` | Optional message to report on failure. |

<br />

### `assertEqual`

    assertEqual(
        first, second, msg=None
    )

Fail if the two objects are unequal as determined by the '==' operator.

### `assertEquals`

    assertEquals(
        *args, **kwargs
    )

### `assertFalse`

    assertFalse(
        expr, msg=None
    )

Check that the expression is false.

### `assertGreater`

    assertGreater(
        a, b, msg=None
    )

Just like self.assertTrue(a \> b), but with a nicer default message.

### `assertGreaterEqual`

    assertGreaterEqual(
        a, b, msg=None
    )

Just like self.assertTrue(a \>= b), but with a nicer default message.

### `assertIn`

    assertIn(
        member, container, msg=None
    )

Just like self.assertTrue(a in b), but with a nicer default message.

### `assertIs`

    assertIs(
        expr1, expr2, msg=None
    )

Just like self.assertTrue(a is b), but with a nicer default message.

### `assertIsInstance`

    assertIsInstance(
        obj, cls, msg=None
    )

Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.

### `assertIsNone`

    assertIsNone(
        obj, msg=None
    )

Same as self.assertTrue(obj is None), with a nicer default message.

### `assertIsNot`

    assertIsNot(
        expr1, expr2, msg=None
    )

Just like self.assertTrue(a is not b), but with a nicer default message.

### `assertIsNotNone`

    assertIsNotNone(
        obj, msg=None
    )

Included for symmetry with assertIsNone.

### `assertItemsEqual`

    assertItemsEqual(
        first, second, msg=None
    )

Asserts that two iterables have the same elements, the same number of times, without regard to order.

    self.assertEqual(Counter(list(first)),
                     Counter(list(second)))

Example:

    - [0, 1, 1] and [1, 0, 1] compare equal.
    - [0, 0, 1] and [0, 1] compare unequal.

### `assertJsonEqual`

    assertJsonEqual(
        first, second, msg=None
    )

Asserts that the JSON objects defined in two strings are equal.

A summary of the differences will be included in the failure message
using assertSameStructure.

<br />

<br />

<br />

| Args ||
|---|---|
| `first` | A string containing JSON to decode and compare to second. |
| `second` | A string containing JSON to decode and compare to first. |
| `msg` | Additional text to include in the failure message. |

<br />

### `assertLen`

    assertLen(
        container, expected_len, msg=None
    )

Asserts that an object has the expected length.

<br />

<br />

<br />

| Args ||
|---|---|
| `container` | Anything that implements the collections.abc.Sized interface. |
| `expected_len` | The expected length of the container. |
| `msg` | Optional message to report on failure. |

<br />

### `assertLess`

    assertLess(
        a, b, msg=None
    )

Just like self.assertTrue(a \< b), but with a nicer default message.

### `assertLessEqual`

    assertLessEqual(
        a, b, msg=None
    )

Just like self.assertTrue(a \<= b), but with a nicer default message.

### `assertListEqual`

    assertListEqual(
        list1, list2, msg=None
    )

A list-specific equality assertion.

<br />

<br />

<br />

| Args ||
|---|---|
| `list1` | The first list to compare. |
| `list2` | The second list to compare. |
| `msg` | Optional message to use on failure instead of a list of differences. |

<br />

### `assertLogs`

    assertLogs(
        logger=None, level=None
    )

Fail unless a log message of level *level* or higher is emitted on *logger_name* or its children.
If omitted, *level* defaults to
INFO and *logger* defaults to the root logger.

This method must be used as a context manager, and will yield
a recording object with two attributes: `output` and `records`.
At the end of the context manager, the `output` attribute will
be a list of the matching formatted log messages and the
`records` attribute will be a list of the corresponding LogRecord
objects.

Example::

    with self.assertLogs('foo', level='INFO') as cm:
        logging.getLogger('foo').info('first message')
        logging.getLogger('foo.bar').error('second message')
    self.assertEqual(cm.output, ['INFO:foo:first message',
                                 'ERROR:foo.bar:second message'])

### `assertMultiLineEqual`

    assertMultiLineEqual(
        first, second, msg=None, **kwargs
    )

Asserts that two multi-line strings are equal.

### `assertNDArrayNear`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2965-L2975)

    assertNDArrayNear(
        ndarray1, ndarray2, err, msg=None
    )

Asserts that two numpy arrays have near values.

<br />

<br />

<br />

| Args ||
|---|---|
| `ndarray1` | a numpy ndarray. |
| `ndarray2` | a numpy ndarray. |
| `err` | a float. The maximum absolute difference allowed. |
| `msg` | Optional message to report on failure. |

<br />

### `assertNear`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2927-L2943)

    assertNear(
        f1, f2, err, msg=None
    )

Asserts that two floats are near each other.

Checks that \|f1 - f2\| \< err and asserts a test failure
if not.

<br />

<br />

<br />

| Args ||
|---|---|
| `f1` | A float value. |
| `f2` | A float value. |
| `err` | A float value. |
| `msg` | An optional string message to append to the failure message. |

<br />

### `assertNoCommonElements`

    assertNoCommonElements(
        expected_seq, actual_seq, msg=None
    )

Checks whether actual iterable and expected iterable are disjoint.

### `assertNotAllClose`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3221-L3244)

    assertNotAllClose(
        a, b, rtol=1e-06, atol=1e-06, msg=None
    )

Assert that two numpy arrays, or Tensors, do not have near values.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The expected numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these. |
| `b` | The actual numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these. |
| `rtol` | relative tolerance. |
| `atol` | absolute tolerance. |
| `msg` | Optional message to report on failure. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `AssertionError` | If `a` and `b` are unexpectedly close at all elements. |

<br />

### `assertNotAllEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3306-L3320)

    assertNotAllEqual(
        a, b, msg=None
    )

Asserts that two numpy arrays or Tensors do not have the same values.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | the expected numpy ndarray or anything can be converted to one. |
| `b` | the actual numpy ndarray or anything can be converted to one. |
| `msg` | Optional message to report on failure. |

<br />

### `assertNotAlmostEqual`

    assertNotAlmostEqual(
        first, second, places=None, msg=None, delta=None
    )

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.

Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most significant digit).

Objects that are equal automatically fail.

### `assertNotAlmostEquals`

    assertNotAlmostEquals(
        *args, **kwargs
    )

### `assertNotEmpty`

    assertNotEmpty(
        container, msg=None
    )

Asserts that an object has non-zero length.

<br />

<br />

<br />

| Args ||
|---|---|
| `container` | Anything that implements the collections.abc.Sized interface. |
| `msg` | Optional message to report on failure. |

<br />

### `assertNotEndsWith`

    assertNotEndsWith(
        actual, unexpected_end, msg=None
    )

Asserts that actual.endswith(unexpected_end) is False.

<br />

<br />

<br />

| Args ||
|---|---|
| `actual` | str |
| `unexpected_end` | str |
| `msg` | Optional message to report on failure. |

<br />

### `assertNotEqual`

    assertNotEqual(
        first, second, msg=None
    )

Fail if the two objects are equal as determined by the '!=' operator.

### `assertNotEquals`

    assertNotEquals(
        *args, **kwargs
    )

### `assertNotIn`

    assertNotIn(
        member, container, msg=None
    )

Just like self.assertTrue(a not in b), but with a nicer default message.

### `assertNotIsInstance`

    assertNotIsInstance(
        obj, cls, msg=None
    )

Included for symmetry with assertIsInstance.

### `assertNotRegex`

    assertNotRegex(
        text, unexpected_regex, msg=None
    )

Fail the test if the text matches the regular expression.

### `assertNotRegexpMatches`

    assertNotRegexpMatches(
        *args, **kwargs
    )

### `assertNotStartsWith`

    assertNotStartsWith(
        actual, unexpected_start, msg=None
    )

Asserts that actual.startswith(unexpected_start) is False.

<br />

<br />

<br />

| Args ||
|---|---|
| `actual` | str |
| `unexpected_start` | str |
| `msg` | Optional message to report on failure. |

<br />

### `assertProtoEquals`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2565-L2608)

    assertProtoEquals(
        expected_message_maybe_ascii, message, msg=None, relative_tolerance=None
    )

Asserts that message is same as parsed expected_message_ascii.

Creates another prototype of message, reads the ascii message into it and
then compares them using self._AssertProtoEqual().

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_message_maybe_ascii` | proto message in original or ascii form. |
| `message` | the message to validate. |
| `msg` | Optional message to report on failure. |
| `relative_tolerance` | float. The allowable difference between the two values being compared is determined by multiplying the relative tolerance by the maximum of the two values. If this is not provided, then all floats are compared using string comparison. |

<br />

### `assertProtoEqualsVersion`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2610-L2619)

    assertProtoEqualsVersion(
        expected,
        actual,
        producer=versions.GRAPH_DEF_VERSION,
        min_consumer=versions.GRAPH_DEF_VERSION_MIN_CONSUMER,
        msg=None
    )

### `assertRaises`

    assertRaises(
        expected_exception, *args, **kwargs
    )

Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments.
If a different type of exception is
raised, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.

If called with the callable and arguments omitted, will return a
context object used like this::

     with self.assertRaises(SomeException):
         do_something()

An optional keyword argument 'msg' can be provided when assertRaises
is used as a context object.

The context manager keeps a reference to the exception as
the 'exception' attribute. This allows you to inspect the
exception after the assertion::

    with self.assertRaises(SomeException) as cm:
        do_something()
    the_exception = cm.exception
    self.assertEqual(the_exception.error_code, 3)

### `assertRaisesIncompatibleShapesError`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3551-L3555)

    assertRaisesIncompatibleShapesError(
        exception_type=https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/errors/InvalidArgumentError
    )

### `assertRaisesOpError`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3547-L3549)

    assertRaisesOpError(
        expected_err_re_or_predicate
    )

### `assertRaisesRegex`

    assertRaisesRegex(
        expected_exception, expected_regex, *args, **kwargs
    )

Asserts that the message in a raised exception matches a regex.

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_exception` | Exception class expected to be raised. |
| `expected_regex` | Regex (re.Pattern object or string) expected to be found in error message. |
| `args` | Function to be called and extra positional args. |
| `kwargs` | Extra kwargs. |
| `msg` | Optional message used in case of failure. Can only be used when assertRaisesRegex is used as a context manager. |

<br />

### `assertRaisesRegexp`

    assertRaisesRegexp(
        expected_exception, expected_regex, *args, **kwargs
    )

Asserts that the message in a raised exception matches a regex.

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_exception` | Exception class expected to be raised. |
| `expected_regex` | Regex (re.Pattern object or string) expected to be found in error message. |
| `args` | Function to be called and extra positional args. |
| `kwargs` | Extra kwargs. |
| `msg` | Optional message used in case of failure. Can only be used when assertRaisesRegex is used as a context manager. |

<br />

### `assertRaisesWithLiteralMatch`

    assertRaisesWithLiteralMatch(
        expected_exception,
        expected_exception_message,
        callable_obj=None,
        *args,
        **kwargs
    )

Asserts that the message in a raised exception equals the given string.

Unlike assertRaisesRegex, this method takes a literal string, not
a regular expression.

with self.assertRaisesWithLiteralMatch(ExType, 'message'):
DoSomething()

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_exception` | Exception class expected to be raised. |
| `expected_exception_message` | String message expected in the raised exception. For a raise exception e, expected_exception_message must equal str(e). |
| `callable_obj` | Function to be called, or None to return a context. |
| `*args` | Extra args. |
| `**kwargs` | Extra kwargs. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A context manager if callable_obj is None. Otherwise, None. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| self.failureException if callable_obj does not raise a matching exception. ||

<br />

### `assertRaisesWithPredicateMatch`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3504-L3543)

    @contextlib.contextmanager
    assertRaisesWithPredicateMatch(
        exception_type, expected_err_re_or_predicate
    )

Returns a context manager to enclose code expected to raise an exception.

If the exception is an OpError, the op stack is also included in the message
predicate search.

<br />

<br />

<br />

| Args ||
|---|---|
| `exception_type` | The expected type of exception that should be raised. |
| `expected_err_re_or_predicate` | If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A context manager to surround code that is expected to raise an exception. ||

<br />

### `assertRegex`

    assertRegex(
        text, expected_regex, msg=None
    )

Fail the test unless the text matches the regular expression.

### `assertRegexMatch`

    assertRegexMatch(
        actual_str, regexes, message=None
    )

Asserts that at least one regex in regexes matches str.

If possible you should use `assertRegex`, which is a simpler
version of this method. `assertRegex` takes a single regular
expression (a string or re compiled object) instead of a list.

#### Notes:

1. This function uses substring matching, i.e. the matching
   succeeds if *any* substring of the error message matches *any*
   regex in the list. This is more convenient for the user than
   full-string matching.

2. If regexes is the empty list, the matching will always fail.

3. Use regexes=\[''\] for a regex that will always pass.

4. '.' matches any single character *except* the newline. To
   match any character, use '(.\|\\n)'.

5. '\^' matches the beginning of each line, not just the beginning
   of the string. Similarly, '$' matches the end of each line.

6. An exception will be thrown if regexes contains an invalid
   regex.

<br />

<br />

<br />

| Args ||
|---|---|
| `actual_str` | The string we try to match with the items in regexes. |
| `regexes` | The regular expressions we want to match against str. See "Notes" above for detailed notes on how this is interpreted. |
| `message` | The message to be printed if the test fails. |

<br />

### `assertRegexpMatches`

    assertRegexpMatches(
        *args, **kwargs
    )

### `assertSameElements`

    assertSameElements(
        expected_seq, actual_seq, msg=None
    )

Asserts that two sequences have the same elements (in any order).

This method, unlike assertCountEqual, doesn't care about any
duplicates in the expected and actual sequences::

    # Doesn't raise an AssertionError
    assertSameElements([1, 1, 1, 0, 0, 0], [0, 1])

If possible, you should use assertCountEqual instead of
assertSameElements.

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_seq` | A sequence containing elements we are expecting. |
| `actual_seq` | The sequence that we are testing. |
| `msg` | The message to be printed if the test fails. |

<br />

### `assertSameStructure`

    assertSameStructure(
        a, b, aname='a', bname='b', msg=None
    )

Asserts that two values contain the same structural content.

The two arguments should be data trees consisting of trees of dicts and
lists. They will be deeply compared by walking into the contents of dicts
and lists; other items will be compared using the == operator.
If the two structures differ in content, the failure message will indicate
the location within the structures where the first difference is found.
This may be helpful when comparing large structures.

Mixed Sequence and Set types are supported. Mixed Mapping types are
supported, but the order of the keys will not be considered in the
comparison.

<br />

<br />

<br />

| Args ||
|---|---|
| `a` | The first structure to compare. |
| `b` | The second structure to compare. |
| `aname` | Variable name to use for the first structure in assertion messages. |
| `bname` | Variable name to use for the second structure. |
| `msg` | Additional text to include in the failure message. |

<br />

### `assertSequenceAlmostEqual`

    assertSequenceAlmostEqual(
        expected_seq, actual_seq, places=None, msg=None, delta=None
    )

An approximate equality assertion for ordered sequences.

Fail if the two sequences are unequal as determined by their value
differences rounded to the given number of decimal places (default 7) and
comparing to zero, or by comparing that the difference between each value
in the two sequences is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant
digits (measured from the most significant digit).

If the two sequences compare equal then they will automatically compare
almost equal.

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_seq` | A sequence containing elements we are expecting. |
| `actual_seq` | The sequence that we are testing. |
| `places` | The number of decimal places to compare. |
| `msg` | The message to be printed if the test fails. |
| `delta` | The OK difference between compared values. |

<br />

### `assertSequenceEqual`

    assertSequenceEqual(
        seq1, seq2, msg=None, seq_type=None
    )

An equality assertion for ordered sequences (like lists and tuples).

For the purposes of this function, a valid ordered sequence type is one
which can be indexed, has a length, and has an equality operator.

<br />

<br />

<br />

| Args ||
|---|---|
| `seq1` | The first sequence to compare. |
| `seq2` | The second sequence to compare. |
| `seq_type` | The expected datatype of the sequences, or None if no datatype should be enforced. |
| `msg` | Optional message to use on failure instead of a list of differences. |

<br />

### `assertSequenceStartsWith`

    assertSequenceStartsWith(
        prefix, whole, msg=None
    )

An equality assertion for the beginning of ordered sequences.

If prefix is an empty sequence, it will raise an error unless whole is also
an empty sequence.

If prefix is not a sequence, it will raise an error if the first element of
whole does not match.

<br />

<br />

<br />

| Args ||
|---|---|
| `prefix` | A sequence expected at the beginning of the whole parameter. |
| `whole` | The sequence in which to look for prefix. |
| `msg` | Optional message to report on failure. |

<br />

### `assertSetEqual`

    assertSetEqual(
        set1, set2, msg=None
    )

A set-specific equality assertion.

<br />

<br />

<br />

| Args ||
|---|---|
| `set1` | The first set to compare. |
| `set2` | The second set to compare. |
| `msg` | Optional message to use on failure instead of a list of differences. |

<br />

assertSetEqual uses ducktyping to support different types of sets, and
is optimized for sets specifically (parameters must support a
difference method).

### `assertShapeEqual`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3557-L3583)

    assertShapeEqual(
        input_a, input_b, msg=None
    )

Asserts that two Numpy or TensorFlow objects have the same shape.

For Tensors, this compares statically known shapes at compile time, not
dynamic shapes at runtime.

<br />

<br />

<br />

| Args ||
|---|---|
| `input_a` | A Numpy ndarray, Numpy scalar, or a Tensor. |
| `input_b` | A Numpy ndarray, Numpy scalar, or a Tensor. |
| `msg` | Optional message to report on failure. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `TypeError` | If the arguments have the wrong type. |

<br />

### `assertStartsWith`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2621-L2632)

    assertStartsWith(
        actual, expected_start, msg=None
    )

Assert that actual.startswith(expected_start) is True.

<br />

<br />

<br />

| Args ||
|---|---|
| `actual` | str |
| `expected_start` | str |
| `msg` | Optional message to report on failure. |

<br />

### `assertTotallyOrdered`

    assertTotallyOrdered(
        *groups, **kwargs
    )

Asserts that total ordering has been implemented correctly.

For example, say you have a class A that compares only on its attribute x.
Comparators other than `__lt__` are omitted for brevity::

    class A(object):
      def __init__(self, x, y):
        self.x = x
        self.y = y

      def __hash__(self):
        return hash(self.x)

      def __lt__(self, other):
        try:
          return self.x < other.x
        except AttributeError:
          return NotImplemented

assertTotallyOrdered will check that instances can be ordered correctly.
For example::

    self.assertTotallyOrdered(
        [None],  # None should come before everything else.
        [1],  # Integers sort earlier.
        [A(1, 'a')],
        [A(2, 'b')],  # 2 is after 1.
        [A(3, 'c'), A(3, 'd')],  # The second argument is irrelevant.
        [A(4, 'z')],
        ['foo'])  # Strings sort last.

<br />

<br />

<br />

| Args ||
|---|---|
| `*groups` | A list of groups of elements. Each group of elements is a list of objects that are equal. The elements in each group must be less than the elements in the group after it. For example, these groups are totally ordered: `[None]`, `[1]`, `[2, 2]`, `[3]`. |
| `**kwargs` | optional msg keyword argument can be passed. |

<br />

### `assertTrue`

    assertTrue(
        expr, msg=None
    )

Check that the expression is true.

### `assertTupleEqual`

    assertTupleEqual(
        tuple1, tuple2, msg=None
    )

A tuple-specific equality assertion.

<br />

<br />

<br />

| Args ||
|---|---|
| `tuple1` | The first tuple to compare. |
| `tuple2` | The second tuple to compare. |
| `msg` | Optional message to use on failure instead of a list of differences. |

<br />

### `assertUrlEqual`

    assertUrlEqual(
        a, b, msg=None
    )

Asserts that urls are equal, ignoring ordering of query params.

### `assertWarns`

    assertWarns(
        expected_warning, *args, **kwargs
    )

Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments.
If a different type of warning is
triggered, it will not be handled: depending on the other
warning filtering rules in effect, it might be silenced, printed
out, or raised as an exception.

If called with the callable and arguments omitted, will return a
context object used like this::

     with self.assertWarns(SomeWarning):
         do_something()

An optional keyword argument 'msg' can be provided when assertWarns
is used as a context object.

The context manager keeps a reference to the first matching
warning as the 'warning' attribute; similarly, the 'filename'
and 'lineno' attributes give you information about the line
of Python code from which the warning was triggered.
This allows you to inspect the warning after the assertion::

    with self.assertWarns(SomeWarning) as cm:
        do_something()
    the_warning = cm.warning
    self.assertEqual(the_warning.some_attribute, 147)

### `assertWarnsRegex`

    assertWarnsRegex(
        expected_warning, expected_regex, *args, **kwargs
    )

Asserts that the message in a triggered warning matches a regexp.
Basic functioning is similar to assertWarns() with the addition
that only warnings whose messages also match the regular expression
are considered successful matches.

<br />

<br />

<br />

| Args ||
|---|---|
| `expected_warning` | Warning class expected to be triggered. |
| `expected_regex` | Regex (re.Pattern object or string) expected to be found in error message. |
| `args` | Function to be called and extra positional args. |
| `kwargs` | Extra kwargs. |
| `msg` | Optional message used in case of failure. Can only be used when assertWarnsRegex is used as a context manager. |

<br />

### `assert_`

    assert_(
        *args, **kwargs
    )

### `cached_session`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2738-L2788)

    @contextlib.contextmanager
    cached_session(
        graph=None, config=None, use_gpu=True, force_gpu=False
    )

Returns a TensorFlow Session for use in executing tests.

This method behaves differently than self.session(): for performance reasons
`cached_session` will by default reuse the same session within the same
test. The session returned by this function will only be closed at the end
of the test (in the TearDown function).

Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and`use_gpu\` are False, all ops are pinned to
the CPU.

#### Example:

    class MyOperatorTest(test_util.TensorFlowTestCase):
      def testMyOperator(self):
        with self.cached_session() as sess:
          valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
          result = MyOperator(valid_input).eval()
          self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
          invalid_input = [-1.0, 2.0, 7.0]
          with self.assertRaisesOpError("negative input not supported"):
            MyOperator(invalid_input).eval()

<br />

<br />

<br />

| Args ||
|---|---|
| `graph` | Optional graph to use during the returned session. |
| `config` | An optional config_pb2.ConfigProto to use to configure the session. |
| `use_gpu` | If True, attempt to run as many ops as possible on GPU. |
| `force_gpu` | If True, pin all ops to `/device:GPU:0`. |

<br />

<br />

<br />

<br />

| Yields ||
|---|---|
| A Session object that should be used as a context manager to surround the graph building and execution code in a test case. ||

<br />

### `captureWritesToStream`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2494-L2537)

    @contextlib.contextmanager
    captureWritesToStream(
        stream
    )

A context manager that captures the writes to a given stream.

This context manager captures all writes to a given stream inside of a
`CapturedWrites` object. When this context manager is created, it yields
the `CapturedWrites` object. The captured contents can be accessed by
calling `.contents()` on the `CapturedWrites`.

For this function to work, the stream must have a file descriptor that
can be modified using `os.dup` and `os.dup2`, and the stream must support
a `.flush()` method. The default python sys.stdout and sys.stderr are
examples of this. Note that this does not work in Colab or Jupyter
notebooks, because those use alternate stdout streams.

#### Example:

    class MyOperatorTest(test_util.TensorFlowTestCase):
      def testMyOperator(self):
        input = [1.0, 2.0, 3.0, 4.0, 5.0]
        with self.captureWritesToStream(sys.stdout) as captured:
          result = MyOperator(input).eval()
        self.assertStartsWith(captured.contents(), "This was printed.")

<br />

<br />

<br />

| Args ||
|---|---|
| `stream` | The stream whose writes should be captured. This stream must have a file descriptor, support writing via using that file descriptor, and must have a `.flush()` method. |

<br />

<br />

<br />

<br />

| Yields ||
|---|---|
| A `CapturedWrites` object that contains all writes to the specified stream made during this context. ||

<br />

### `checkedThread`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2906-L2924)

    checkedThread(
        target, args=None, kwargs=None
    )

Returns a Thread wrapper that asserts 'target' completes successfully.

This method should be used to create all threads in test cases, as
otherwise there is a risk that a thread will silently fail, and/or
assertions made in the thread will not be respected.

<br />

<br />

<br />

| Args ||
|---|---|
| `target` | A callable object to be executed in the thread. |
| `args` | The argument tuple for the target invocation. Defaults to (). |
| `kwargs` | A dictionary of keyword arguments for the target invocation. Defaults to {}. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A wrapper for threading.Thread that supports start() and join() methods. ||

<br />

### `countTestCases`

    countTestCases()

### `create_tempdir`

    create_tempdir(
        name=None, cleanup=None
    )

Create a temporary directory specific to the test.

> [!NOTE]
> **Note:** The directory and its contents will be recursively cleared before creation. This ensures that there is no pre-existing state.

This creates a named directory on disk that is isolated to this test, and
will be properly cleaned up by the test. This avoids several pitfalls of
creating temporary directories for test purposes, as well as makes it easier
to setup directories and verify their contents. For example::

    def test_foo(self):
      out_dir = self.create_tempdir()
      out_log = out_dir.create_file('output.log')
      expected_outputs = [
          os.path.join(out_dir, 'data-0.txt'),
          os.path.join(out_dir, 'data-1.txt'),
      ]
      code_under_test(out_dir)
      self.assertTrue(os.path.exists(expected_paths[0]))
      self.assertTrue(os.path.exists(expected_paths[1]))
      self.assertEqual('foo', out_log.read_text())

See also: :meth:`create_tempfile` for creating temporary files.

<br />

<br />

<br />

| Args ||
|---|---|
| `name` | Optional name of the directory. If not given, a unique name will be generated and used. |
| `cleanup` | Optional cleanup policy on when/if to remove the directory (and all its contents) at the end of the test. If None, then uses :attr:`tempfile_cleanup`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A _TempDir representing the created directory; see _TempDir class docs for usage. ||

<br />

### `create_tempfile`

    create_tempfile(
        file_path=None,
        content=None,
        mode='w',
        encoding='utf8',
        errors='strict',
        cleanup=None
    )

Create a temporary file specific to the test.

This creates a named file on disk that is isolated to this test, and will
be properly cleaned up by the test. This avoids several pitfalls of
creating temporary files for test purposes, as well as makes it easier
to setup files, their data, read them back, and inspect them when
a test fails. For example::

    def test_foo(self):
      output = self.create_tempfile()
      code_under_test(output)
      self.assertGreater(os.path.getsize(output), 0)
      self.assertEqual('foo', output.read_text())

> [!NOTE]
> **Note:** This will zero-out the file. This ensures there is no pre-existing state. NOTE: If the file already exists, it will be made writable and overwritten.

See also: :meth:`create_tempdir` for creating temporary directories, and
`_TempDir.create_file` for creating files within a temporary directory.

<br />

<br />

<br />

| Args ||
|---|---|
| `file_path` | Optional file path for the temp file. If not given, a unique file name will be generated and used. Slashes are allowed in the name; any missing intermediate directories will be created. NOTE: This path is the path that will be cleaned up, including any directories in the path, e.g., `'foo/bar/baz.txt'` will `rm -r foo`. |
| `content` | Optional string or bytes to initially write to the file. If not specified, then an empty file is created. |
| `mode` | Mode string to use when writing content. Only used if `content` is non-empty. |
| `encoding` | Encoding to use when writing string content. Only used if `content` is text. |
| `errors` | How to handle text to bytes encoding errors. Only used if `content` is text. |
| `cleanup` | Optional cleanup policy on when/if to remove the directory (and all its contents) at the end of the test. If None, then uses :attr:`tempfile_cleanup`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A _TempFile representing the created file; see _TempFile class docs for usage. ||

<br />

### `debug`

    debug()

Run the test without collecting errors in a TestResult

### `defaultTestResult`

    defaultTestResult()

### `doClassCleanups`

    @classmethod
    doClassCleanups()

Execute all class cleanup functions.
Normally called for you after
tearDownClass.

### `doCleanups`

    doCleanups()

Execute all cleanup functions.
Normally called for you after
tearDown.

### `enter_context`

    enter_context()

### `evaluate`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2674-L2691)

    evaluate(
        tensors
    )

Evaluates tensors and returns numpy values.

<br />

<br />

<br />

| Args ||
|---|---|
| `tensors` | A Tensor or a nested list/tuple of Tensors. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| tensors numpy values. ||

<br />

### `evaluate_if_both_tensors`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L3003-L3009)

    evaluate_if_both_tensors(
        a, b
    )

### `fail`

    fail(
        msg=None, user_msg=None
    ) -> NoReturn

Fail immediately with the given standard message and user message.

### `failIf`

    failIf(
        *args, **kwargs
    )

### `failIfAlmostEqual`

    failIfAlmostEqual(
        *args, **kwargs
    )

### `failIfEqual`

    failIfEqual(
        *args, **kwargs
    )

### `failUnless`

    failUnless(
        *args, **kwargs
    )

### `failUnlessAlmostEqual`

    failUnlessAlmostEqual(
        *args, **kwargs
    )

### `failUnlessEqual`

    failUnlessEqual(
        *args, **kwargs
    )

### `failUnlessRaises`

    failUnlessRaises(
        *args, **kwargs
    )

### `get_temp_dir`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2476-L2492)

    get_temp_dir()

Returns a unique temporary directory for the test to use.

If you call this method multiple times during in a test, it will return the
same folder. However, across different runs the directories will be
different. This will ensure that across different runs tests will not be
able to pollute each others environment.
If you need multiple unique directories within a single test, you should
use tempfile.mkdtemp as follows:
tempfile.mkdtemp(dir=self.get_temp_dir()):

<br />

<br />

<br />

| Returns ||
|---|---|
| string, the path to the unique temporary directory created for this test. ||

<br />

### `id`

    id()

### `run`

    run(
        result=None
    )

### `session`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2694-L2736)

    @contextlib.contextmanager
    session(
        graph=None, config=None, use_gpu=True, force_gpu=False
    )

A context manager for a TensorFlow Session for use in executing tests.

Note that this will set this session and the graph as global defaults.

Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and`use_gpu\` are False, all ops are pinned to
the CPU.

#### Example:

    class MyOperatorTest(test_util.TensorFlowTestCase):
      def testMyOperator(self):
        with self.session():
          valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
          result = MyOperator(valid_input).eval()
          self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
          invalid_input = [-1.0, 2.0, 7.0]
          with self.assertRaisesOpError("negative input not supported"):
            MyOperator(invalid_input).eval()

<br />

<br />

<br />

| Args ||
|---|---|
| `graph` | Optional graph to use during the returned session. |
| `config` | An optional config_pb2.ConfigProto to use to configure the session. |
| `use_gpu` | If True, attempt to run as many ops as possible on GPU. |
| `force_gpu` | If True, pin all ops to `/device:GPU:0`. |

<br />

<br />

<br />

<br />

| Yields ||
|---|---|
| A Session object that should be used as a context manager to surround the graph building and execution code in a test case. ||

<br />

### `setUp`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2432-L2456)

    setUp()

Hook method for setting up the test fixture before exercising it.

### `setUpClass`

    @classmethod
    setUpClass()

Hook method for setting up class fixture before running tests in the class.

### `shortDescription`

    shortDescription()

Formats both the test method name and the first line of its docstring.

If no docstring is given, only returns the method name.

This method overrides unittest.TestCase.shortDescription(), which
only returns the first line of the docstring, obscuring the name
of the test upon failure.

<br />

<br />

<br />

| Returns ||
|---|---|
| `desc` | A short description of a test method. |

<br />

### `skipTest`

    skipTest(
        reason
    )

Skip this test.

### `subTest`

    @contextlib.contextmanager
    subTest(
        msg=_subtest_msg_sentinel, **params
    )

Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters.
A failure in the subtest marks the test
case as failed but resumes execution at the end of the enclosed
block, allowing further test code to be executed.

### `tearDown`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2458-L2469)

    tearDown()

Hook method for deconstructing the test fixture after testing it.

### `tearDownClass`

    @classmethod
    tearDownClass()

Hook method for deconstructing the class fixture after running all tests in the class.

### `test_session`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/test_util.py#L2790-L2816)

    @contextlib.contextmanager
    test_session(
        graph=None, config=None, use_gpu=True, force_gpu=False
    )

Use cached_session instead. (deprecated)

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use `self.session()` or `self.cached_session()` instead.

### `__call__`

    __call__(
        *args, **kwds
    )

Call self as a function.

### `__eq__`

    __eq__(
        other
    )

Return self==value.

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| longMessage | `True` |
| maxDiff | `1600` |
| tempfile_cleanup | `<TempFileCleanup.ALWAYS: 'always'>` |

<br />