From: Ben Darnell Date: Tue, 28 Dec 2021 20:17:45 +0000 (-0500) Subject: testing: Move setup_with_context_manager to testing module X-Git-Tag: v6.2.0b1~36^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ebe6d07eead620e4a637dd5dc4d962248a913cdb;p=thirdparty%2Ftornado.git testing: Move setup_with_context_manager to testing module --- diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index e9466341e..b3a223318 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -16,10 +16,15 @@ from tornado.escape import native_str from tornado import gen from tornado.ioloop import IOLoop, TimeoutError, PeriodicCallback from tornado.log import app_log -from tornado.testing import AsyncTestCase, bind_unused_port, ExpectLog, gen_test +from tornado.testing import ( + AsyncTestCase, + bind_unused_port, + ExpectLog, + gen_test, + setup_with_context_manager, +) from tornado.test.util import ( ignore_deprecation, - setup_with_context_manager, skipIfNonUnix, skipOnTravis, ) diff --git a/tornado/test/util.py b/tornado/test/util.py index b0d62af34..bcb9bbde2 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -112,11 +112,3 @@ def ignore_deprecation(): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) yield - - -# From https://nedbatchelder.com/blog/201508/using_context_managers_in_test_setup.html -def setup_with_context_manager(testcase, cm): - """Use a contextmanager to setUp a test case.""" - val = cm.__enter__() - testcase.addCleanup(cm.__exit__, None, None, None) - return val diff --git a/tornado/testing.py b/tornado/testing.py index 0996f7a46..cdea88ee0 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -762,6 +762,14 @@ class ExpectLog(logging.Filter): raise Exception("did not get expected log message") +# From https://nedbatchelder.com/blog/201508/using_context_managers_in_test_setup.html +def setup_with_context_manager(testcase: unittest.TestCase, cm: Any) -> Any: + """Use a contextmanager to setUp a test case.""" + val = cm.__enter__() + testcase.addCleanup(cm.__exit__, None, None, None) + return val + + def main(**kwargs: Any) -> None: """A simple test runner.