mirror of https://github.com/pallets/flask.git
Kill classes in test_regression
This commit is contained in:
parent
f8a778deae
commit
71dae37733
|
|
@ -19,14 +19,10 @@ import threading
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_gc_lock = threading.Lock()
|
_gc_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
class _NoLeakAsserter(object):
|
class assert_no_leak(object):
|
||||||
|
|
||||||
def __init__(self, testcase):
|
|
||||||
self.testcase = testcase
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
gc.disable()
|
gc.disable()
|
||||||
|
|
@ -47,7 +43,7 @@ class _NoLeakAsserter(object):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
new_objects = len(gc.get_objects())
|
new_objects = len(gc.get_objects())
|
||||||
if new_objects > self.old_objects:
|
if new_objects > self.old_objects:
|
||||||
self.testcase.fail('Example code leaked')
|
pytest.fail('Example code leaked')
|
||||||
_gc_lock.release()
|
_gc_lock.release()
|
||||||
gc.enable()
|
gc.enable()
|
||||||
|
|
||||||
|
|
@ -56,12 +52,7 @@ class _NoLeakAsserter(object):
|
||||||
# ported Flask to Python 3.
|
# ported Flask to Python 3.
|
||||||
@pytest.mark.skipif(os.environ.get('RUN_FLASK_MEMORY_TESTS') != '1',
|
@pytest.mark.skipif(os.environ.get('RUN_FLASK_MEMORY_TESTS') != '1',
|
||||||
reason='Turned off due to envvar.')
|
reason='Turned off due to envvar.')
|
||||||
class TestMemory(object):
|
def test_memory_consumption():
|
||||||
|
|
||||||
def assert_no_leak(self):
|
|
||||||
return _NoLeakAsserter(self)
|
|
||||||
|
|
||||||
def test_memory_consumption(self):
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
|
@ -80,19 +71,18 @@ class TestMemory(object):
|
||||||
# This test only works on CPython 2.7.
|
# This test only works on CPython 2.7.
|
||||||
if sys.version_info >= (2, 7) and \
|
if sys.version_info >= (2, 7) and \
|
||||||
not hasattr(sys, 'pypy_translation_info'):
|
not hasattr(sys, 'pypy_translation_info'):
|
||||||
with self.assert_no_leak():
|
with assert_no_leak():
|
||||||
for x in range(10):
|
for x in range(10):
|
||||||
fire()
|
fire()
|
||||||
|
|
||||||
def test_safe_join_toplevel_pardir(self):
|
|
||||||
|
def test_safe_join_toplevel_pardir():
|
||||||
from flask.helpers import safe_join
|
from flask.helpers import safe_join
|
||||||
with pytest.raises(NotFound):
|
with pytest.raises(NotFound):
|
||||||
safe_join('/foo', '..')
|
safe_join('/foo', '..')
|
||||||
|
|
||||||
|
|
||||||
class TestException(object):
|
def test_aborting():
|
||||||
|
|
||||||
def test_aborting(self):
|
|
||||||
class Foo(Exception):
|
class Foo(Exception):
|
||||||
whatever = 42
|
whatever = 42
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue