diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-09 15:16:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 15:16:09 (GMT) |
commit | 934a24c641da5bc4bdb724e901adc20f9a5dff40 (patch) | |
tree | c9b28fea41d6b5b0dc33b1a16f4fca0210681a50 /Lib/test/_test_atexit.py | |
parent | 2c2ee83c4db4dbd54017dc364bbefc70fa75ea5d (diff) | |
download | cpython-934a24c641da5bc4bdb724e901adc20f9a5dff40.zip cpython-934a24c641da5bc4bdb724e901adc20f9a5dff40.tar.gz cpython-934a24c641da5bc4bdb724e901adc20f9a5dff40.tar.bz2 |
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002) (GH-30005)
(cherry picked from commit f0d290d25cad66e615ada68ba190b8a23ac1deaa)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test/_test_atexit.py')
-rw-r--r-- | Lib/test/_test_atexit.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/_test_atexit.py b/Lib/test/_test_atexit.py index a316585..55d2808 100644 --- a/Lib/test/_test_atexit.py +++ b/Lib/test/_test_atexit.py @@ -116,6 +116,21 @@ class GeneralTest(unittest.TestCase): atexit._run_exitfuncs() self.assertEqual(l, [5]) + def test_atexit_with_unregistered_function(self): + # See bpo-46025 for more info + def func(): + atexit.unregister(func) + 1/0 + atexit.register(func) + try: + with support.catch_unraisable_exception() as cm: + atexit._run_exitfuncs() + self.assertEqual(cm.unraisable.object, func) + self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError) + self.assertEqual(type(cm.unraisable.exc_value), ZeroDivisionError) + finally: + atexit.unregister(func) + if __name__ == "__main__": unittest.main() |