Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 24, 2024
1 parent 1e41917 commit 1312af7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
20 changes: 0 additions & 20 deletions pyftpdlib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# found in the LICENSE file.


import atexit
import contextlib
import functools
import logging
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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))
12 changes: 12 additions & 0 deletions pyftpdlib/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
tearDown(), setUpClass(), tearDownClass() methods for each test class.
"""

import atexit
import os
import threading
import warnings

Expand All @@ -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
Expand Down Expand Up @@ -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))

0 comments on commit 1312af7

Please sign in to comment.