MCPcopy Index your code
hub / github.com/python/cpython / test_exit_on_shutdown

Method test_exit_on_shutdown

Lib/test/test_tempfile.py:1949–1971  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1947 self.assertIn("ResourceWarning: Implicitly cleaning up", err)
1948
1949 def test_exit_on_shutdown(self):
1950 # Issue #22427
1951 with self.do_create() as dir:
1952 code = """if True:
1953 import sys
1954 import tempfile
1955 import warnings
1956
1957 def generator():
1958 with tempfile.TemporaryDirectory(dir={dir!r}) as tmp:
1959 yield tmp
1960 g = generator()
1961 sys.stdout.buffer.write(next(g).encode())
1962
1963 warnings.filterwarnings("always", category=ResourceWarning)
1964 """.format(dir=dir)
1965 rc, out, err = script_helper.assert_python_ok("-c", code)
1966 tmp_name = out.decode().strip()
1967 self.assertFalse(os.path.exists(tmp_name),
1968 "TemporaryDirectory %s exists after cleanup" % tmp_name)
1969 err = err.decode('utf-8', 'backslashreplace')
1970 self.assertNotIn("Exception ", err)
1971 self.assertIn("ResourceWarning: Implicitly cleaning up", err)
1972
1973 def test_warnings_on_cleanup(self):
1974 # ResourceWarning will be triggered by __del__

Callers

nothing calls this directly

Calls 9

do_createMethod · 0.95
assert_python_okMethod · 0.80
assertFalseMethod · 0.80
assertNotInMethod · 0.80
assertInMethod · 0.80
formatMethod · 0.45
stripMethod · 0.45
decodeMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected