Settings
For clients that wish to temporarily alter any of the previously described behaviors, a handful of settings can be controlled at the module level. All values default to True
unless otherwise noted.
HIDE_TRACEBACK_IN_HOOKS
When an exception occurs in patched method, this traceback is hidden by default for pytest
. If this information is required to debug a complex issue enable it as follows:
import datafiles
datafiles.settings.HIDE_TRACEBACK_IN_HOOKS = False
HOOKS_ENABLED
When running unit tests for a client using datafiles
,
it can be helpful to disable automatic loading/saving of models for performance and to avoid writing files to disk:
import datafiles
def pytest_runtest_setup(item):
"""Disable file storage during unit tests."""
datafiles.settings.HOOKS_ENABLED = False
INDENT_YAML_BLOCKS
In datafiles >= 0.4
, YAML blocks are now indented by default, like so:
items:
- 1
- 2
- 3
To make it easier to upgrade to this version, a client can disable this functionality:
import datafiles
datafiles.settings.INDENT_YAML_BLOCKS = False
to produce YAML like:
items:
- 4
- 5
- 6
MINIMIZE_LIST_DIFFS
When serializing lists, datafiles
intentionally deviates from the semantic representation of an empty list to optimize for the use case of storing YAML files in version control.
By storing any empty list of items
as:
items:
-
adding or removing an item always results in a one-line change. Where as adding items to items: []
produces a noisier diff and requires knowledge of the YAML specification to edit files by hand.
To disable this behavior:
import datafiles
datafiles.settings.MINIMIZE_LIST_DIFFS = False
YAML_LIBRARY
This setting controls the underlying YAML library used to read and write files. The following options are available:
'ruamel.yaml'
(default)'PyYAML'
WRITE_DELAY
One some file systems, the modification time of a file (st_mtime
) is unchanged if a file is read immediately after writing. This may cause intermittent issues if your use case involves rapidly changing files.
To compensate for this, a short delay can be inserted after datafiles
writes to the file system:
import datafiles
datafiles.settings.WRITE_DELAY = 0.01 # seconds