diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-05-08 15:12:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 15:12:19 (GMT) |
commit | c63c8ac2389d715c761f56bfcf17a685b62a0bd3 (patch) | |
tree | 5b4e82a1f54099f9a75217ac0045aa071dcf4188 /Lib/test/test_posix.py | |
parent | a85bdd7e025f8b87b88d914f4df8f0b620398ea9 (diff) | |
download | cpython-c63c8ac2389d715c761f56bfcf17a685b62a0bd3.zip cpython-c63c8ac2389d715c761f56bfcf17a685b62a0bd3.tar.gz cpython-c63c8ac2389d715c761f56bfcf17a685b62a0bd3.tar.bz2 |
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase.
Add method enterAsyncContext() in IsolatedAsyncioTestCase.
Add function enterModuleContext().
(cherry picked from commit 086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r-- | Lib/test/test_posix.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index f44b8d0..28e5e90 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -53,19 +53,13 @@ class PosixTester(unittest.TestCase): def setUp(self): # create empty file + self.addCleanup(os_helper.unlink, os_helper.TESTFN) with open(os_helper.TESTFN, "wb"): pass - self.teardown_files = [ os_helper.TESTFN ] - self._warnings_manager = warnings_helper.check_warnings() - self._warnings_manager.__enter__() + self.enterContext(warnings_helper.check_warnings()) warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning) - def tearDown(self): - for teardown_file in self.teardown_files: - os_helper.unlink(teardown_file) - self._warnings_manager.__exit__(None, None, None) - def testNoArgFunctions(self): # test posix functions which take no arguments and have # no side-effects which we need to cleanup (e.g., fork, wait, abort) @@ -973,8 +967,8 @@ class PosixTester(unittest.TestCase): self.assertTrue(hasattr(testfn_st, 'st_flags')) + self.addCleanup(os_helper.unlink, _DUMMY_SYMLINK) os.symlink(os_helper.TESTFN, _DUMMY_SYMLINK) - self.teardown_files.append(_DUMMY_SYMLINK) dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) def chflags_nofollow(path, flags): |