| 1824 | self._cached_session = None |
| 1825 | |
| 1826 | def setUp(self): |
| 1827 | self._ClearCachedSession() |
| 1828 | random.seed(random_seed.DEFAULT_GRAPH_SEED) |
| 1829 | np.random.seed(random_seed.DEFAULT_GRAPH_SEED) |
| 1830 | # Note: The following line is necessary because some test methods may error |
| 1831 | # out from within nested graph contexts (e.g., via assertRaises and |
| 1832 | # assertRaisesRegexp), which may leave ops._default_graph_stack non-empty |
| 1833 | # under certain versions of Python. That would cause |
| 1834 | # ops.reset_default_graph() to throw an exception if the stack were not |
| 1835 | # cleared first. |
| 1836 | ops._default_graph_stack.reset() # pylint: disable=protected-access |
| 1837 | ops.reset_default_graph() |
| 1838 | random_seed.set_random_seed(random_seed.DEFAULT_GRAPH_SEED) |
| 1839 | # Reset summary writer in case another test used set_as_default() with their |
| 1840 | # summary writer. |
| 1841 | context.context().summary_writer = None |
| 1842 | |
| 1843 | # Avoiding calling setUp() for the poorly named test_session method. |
| 1844 | if self.id().endswith(".test_session"): |
| 1845 | self.skipTest("Not a test.") |
| 1846 | |
| 1847 | def tearDown(self): |
| 1848 | for thread in self._threads: |