From 1312af73a6d256b3036ffd96a855d6920336a075 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 24 Jun 2024 13:39:09 +0200 Subject: [PATCH] refact --- pyftpdlib/test/__init__.py | 20 -------------------- pyftpdlib/test/conftest.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/pyftpdlib/test/__init__.py b/pyftpdlib/test/__init__.py index 1dabe082..b9a4ab08 100644 --- a/pyftpdlib/test/__init__.py +++ b/pyftpdlib/test/__init__.py @@ -3,7 +3,6 @@ # found in the LICENSE file. -import atexit import contextlib import functools import logging @@ -197,18 +196,6 @@ def wrapper(self, *args, **kwargs): return wrapper -def cleanup(): - """Cleanup function executed on interpreter exit.""" - map = IOLoop.instance().socket_map - for x in list(map.values()): - try: - sys.stderr.write("garbage: %s\n" % repr(x)) - x.close() - except Exception: # noqa - pass - map.clear() - - class retry: """A retry decorator.""" @@ -485,10 +472,3 @@ def stop(self): else: # Windows FtpdMultiprocWrapper = FtpdThreadWrapper - - -@atexit.register -def exit_cleanup(): - for name in os.listdir(ROOT_DIR): - if name.startswith(TESTFN_PREFIX): - safe_rmpath(os.path.join(ROOT_DIR, name)) diff --git a/pyftpdlib/test/conftest.py b/pyftpdlib/test/conftest.py index ed7114a1..ece36afa 100644 --- a/pyftpdlib/test/conftest.py +++ b/pyftpdlib/test/conftest.py @@ -14,6 +14,8 @@ tearDown(), setUpClass(), tearDownClass() methods for each test class. """ +import atexit +import os import threading import warnings @@ -23,6 +25,9 @@ from pyftpdlib.ioloop import IOLoop from . import POSIX +from . import ROOT_DIR +from . import TESTFN_PREFIX +from . import safe_rmpath # set it to True to raise an exception instead of warning @@ -95,3 +100,10 @@ def teardown_method(setup_ctx, request): def for_each_test_method(request): ctx = setup_method(request.node.nodeid) request.addfinalizer(lambda: teardown_method(ctx, request)) + + +@atexit.register +def on_exit(): + for name in os.listdir(ROOT_DIR): + if name.startswith(TESTFN_PREFIX): + safe_rmpath(os.path.join(ROOT_DIR, name))