Make testing for orphaned file handles and temporary files optional.
Allows for running tests in parallel.
This commit is contained in:
@@ -95,6 +95,9 @@ Other changes
|
|||||||
- Add custom test runner replacing the custom management command runtests.
|
- Add custom test runner replacing the custom management command runtests.
|
||||||
The 'test-all' Makefile target that called the `runtests` command has been removed too.
|
The 'test-all' Makefile target that called the `runtests` command has been removed too.
|
||||||
|
|
||||||
|
- Testing for orphaned temporary files and orphaned file handles is now optional and
|
||||||
|
controlled by the COMMON_TEST_FILE_HANDLES and COMMON_TEST_FILE_HANDLES settings.
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
--------
|
--------
|
||||||
- Removal of the OCR_TESSERACT_PATH configuration setting.
|
- Removal of the OCR_TESSERACT_PATH configuration setting.
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import os
|
|||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from ..settings import setting_temporary_directory
|
from ..settings import setting_temporary_directory
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +34,34 @@ class ContentTypeCheckMixin(object):
|
|||||||
self.client = CustomClient()
|
self.client = CustomClient()
|
||||||
|
|
||||||
|
|
||||||
|
class OpenFileCheckMixin(object):
|
||||||
|
def _get_descriptor_count(self):
|
||||||
|
process = psutil.Process()
|
||||||
|
return process.num_fds()
|
||||||
|
|
||||||
|
def _get_open_files(self):
|
||||||
|
process = psutil.Process()
|
||||||
|
return process.open_files()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(OpenFileCheckMixin, self).setUp()
|
||||||
|
if getattr(settings, 'COMMON_TEST_FILE_HANDLES', False):
|
||||||
|
self._open_files = self._get_open_files()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
if getattr(settings, 'COMMON_TEST_FILE_HANDLES', False) and not getattr(self, '_skip_file_descriptor_test', False):
|
||||||
|
for new_open_file in self._get_open_files():
|
||||||
|
self.assertFalse(
|
||||||
|
new_open_file not in self._open_files,
|
||||||
|
msg='File descriptor leak. The number of file descriptors '
|
||||||
|
'at the start and at the end of the test are not the same.'
|
||||||
|
)
|
||||||
|
|
||||||
|
self._skip_file_descriptor_test = False
|
||||||
|
|
||||||
|
super(OpenFileCheckMixin, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
class TempfileCheckMixin(object):
|
class TempfileCheckMixin(object):
|
||||||
# Ignore the jvmstat instrumentation and GitLab's CI .config files
|
# Ignore the jvmstat instrumentation and GitLab's CI .config files
|
||||||
ignore_globs = ('hsperfdata_*', '.config', '.cache')
|
ignore_globs = ('hsperfdata_*', '.config', '.cache')
|
||||||
@@ -57,43 +87,18 @@ class TempfileCheckMixin(object):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TempfileCheckMixin, self).setUp()
|
super(TempfileCheckMixin, self).setUp()
|
||||||
self._temporary_items = self._get_temporary_entries()
|
if getattr(settings, 'COMMON_TEST_TEMP_FILES', False):
|
||||||
|
self._temporary_items = self._get_temporary_entries()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
final_temporary_items = self._get_temporary_entries()
|
if getattr(settings, 'COMMON_TEST_TEMP_FILES', False):
|
||||||
self.assertEqual(
|
final_temporary_items = self._get_temporary_entries()
|
||||||
self._temporary_items, final_temporary_items,
|
self.assertEqual(
|
||||||
msg='Orphan temporary file. The number of temporary files and/or '
|
self._temporary_items, final_temporary_items,
|
||||||
'directories at the start and at the end of the test are not the '
|
msg='Orphan temporary file. The number of temporary files and/or '
|
||||||
'same. Orphan entries: {}'.format(
|
'directories at the start and at the end of the test are not the '
|
||||||
','.join(final_temporary_items - self._temporary_items)
|
'same. Orphan entries: {}'.format(
|
||||||
)
|
','.join(final_temporary_items - self._temporary_items)
|
||||||
)
|
|
||||||
super(TempfileCheckMixin, self).tearDown()
|
|
||||||
|
|
||||||
|
|
||||||
class OpenFileCheckMixin(object):
|
|
||||||
def _get_descriptor_count(self):
|
|
||||||
process = psutil.Process()
|
|
||||||
return process.num_fds()
|
|
||||||
|
|
||||||
def _get_open_files(self):
|
|
||||||
process = psutil.Process()
|
|
||||||
return process.open_files()
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(OpenFileCheckMixin, self).setUp()
|
|
||||||
self._open_files = self._get_open_files()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
if not getattr(self, '_skip_file_descriptor_test', False):
|
|
||||||
for new_open_file in self._get_open_files():
|
|
||||||
self.assertFalse(
|
|
||||||
new_open_file not in self._open_files,
|
|
||||||
msg='File descriptor leak. The number of file descriptors '
|
|
||||||
'at the start and at the end of the test are not the same.'
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
self._skip_file_descriptor_test = False
|
super(TempfileCheckMixin, self).tearDown()
|
||||||
|
|
||||||
super(OpenFileCheckMixin, self).tearDown()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user