MCPcopy
hub / github.com/tornadoweb/tornado / setup_with_context_manager

Function setup_with_context_manager

tornado/testing.py:756–770  ·  view source on GitHub ↗

Use a context manager to setUp a test case. Example:: def setUp(self): setup_with_context_manager(self, warnings.catch_warnings()) warnings.filterwarnings("ignore", category=DeprecationWarning) # The catch_warnings context manager will be deactivated

(testcase: unittest.TestCase, cm: Any)

Source from the content-addressed store, hash-verified

754
755# From https://nedbatchelder.com/blog/201508/using_context_managers_in_test_setup.html
756def setup_with_context_manager(testcase: unittest.TestCase, cm: Any) -> Any:
757 """Use a context manager to setUp a test case.
758
759 Example::
760
761 def setUp(self):
762 setup_with_context_manager(self, warnings.catch_warnings())
763 warnings.filterwarnings("ignore", category=DeprecationWarning)
764 # The catch_warnings context manager will be deactivated
765 # automatically in tearDown.
766
767 """
768 val = cm.__enter__()
769 testcase.addCleanup(cm.__exit__, None, None, None)
770 return val
771
772
773def main(**kwargs: Any) -> None:

Callers 4

setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.85

Calls 1

__enter__Method · 0.45

Tested by

no test coverage detected