[testlib] Deprecate with_tempdir (Closes #8267966)

Recommend tempfile.TemporaryDirectory, available in tempfile from Python 3.4 or from backports.tempfile otherwise.

authorDenis Laxalde <denis.laxalde@logilab.fr>
changeseta46185f35ce7
branchdefault
phasepublic
hiddenno
parent revision#019d28605cb5 [modutils] Copy back modpath_from_file from astroid
child revision#2936f44eed48 Rename pytest executable into logilab-pytest
files modified by this revision
logilab/common/testlib.py
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1477302934 -7200
# Mon Oct 24 11:55:34 2016 +0200
# Node ID a46185f35ce7cf79a19ed9cc2b91ae93c5327bc5
# Parent 019d28605cb5c7abd885597de5f774aceaeb467b
[testlib] Deprecate with_tempdir (Closes #8267966)

Recommend tempfile.TemporaryDirectory, available in tempfile from Python 3.4
or from `backports.tempfile`_ otherwise.

.. _`backports.tempfile`: https://pypi.python.org/pypi/backports.tempfile

diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
@@ -54,11 +54,11 @@
1  import warnings
2  from shutil import rmtree
3  from operator import itemgetter
4  from inspect import isgeneratorfunction
5 
6 -from six import string_types
7 +from six import PY2, string_types
8  from six.moves import builtins, range, configparser, input
9 
10  from logilab.common.deprecation import deprecated
11 
12  import unittest as unittest_legacy
@@ -88,10 +88,12 @@
13 
14  # used by unittest to count the number of relevant levels in the traceback
15  __unittest = 1
16 
17 
18 +@deprecated('with_tempdir is deprecated, use {0}.TemporaryDirectory.'.format(
19 +    'tempfile' if not PY2 else 'backports.tempfile'))
20  def with_tempdir(callable):
21      """A decorator ensuring no temporary file left when the function return
22      Work only for temporary file created with the tempfile module"""
23      if isgeneratorfunction(callable):
24          def proxy(*args, **kwargs):