diff --git a/tests/test_api.py b/tests/test_api.py index 1f6435c..281faf0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -444,8 +444,6 @@ def test_concurrent_put(app, transactional_db, settings): response = app.put_json(url, params=payload) assert response.status_code == 201 - pool = ThreadPool(pool_count) - def f(i): from django.db import connection if i % 2 == 0: @@ -455,6 +453,8 @@ def test_concurrent_put(app, transactional_db, settings): connection.close() return i - results = pool.map(f, range(put_count)) + with ThreadPool(pool_count) as pool: + results = pool.map(f, range(put_count)) + assert len(results) == put_count assert sum(len(files) for _, _, files in os.walk(settings.MEDIA_ROOT)) == 1 diff --git a/tests/utils.py b/tests/utils.py index a25e0c1..89a0b18 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -18,7 +18,8 @@ def get_tests_file(filename): def get_tests_file_content(filename): - return open(get_tests_file(filename), 'rb').read() + with open(get_tests_file(filename), 'rb') as fd: + return fd.read() def create_service(name, password=None):