Files and tests
For Automatic Configuration
If your project uses automatic configuration, your files and tests properties will be automatically set based on your project’s configuration. You may configure different or additional files and tests when using automatic configuration:
Replace automatic configuration files and/or tests
You may force Wallaby to completely ignore the files and/or tests properties that are automatically set by Wallaby’s automatic configuration by creating a files or tests property with an array of patterns.
def configure():
return {
'autoDetect': True,
# replace 'files' automatic configuration settings
'files': ['src/**/*.py'],
# replace 'tests' automatic configuration settings
'tests': ['tests/**/test_*.py'],
}
For Manual Configuration
Files
The files array property specifies an array of source files or file name patterns.
Make sure that all files used by your tests are listed in the config files list. Wallaby uses its own cache to process/instrument files and run tests, so it has to copy used files there. For example, if your tests load some data files, they should be included in the files list.
Tests
The tests array property specifies an array of test files or test file name patterns. IMPORTANT: only actual test files should be specified in the tests list. Any test helpers or fixtures should be specified in the files list.
Both files and tests paths are specified relative to the location of the Wallaby configuration file.
For example, the configuration sample below makes Wallaby track all .py files in the src folder. The sample also includes all test files from the tests folder whose name starts with test_.
def configure():
return {
'files': ['src/**/*.py'],
'tests': ['tests/**/test_*.py'],
}Files and tests are the only mandatory configuration properties; the rest are optional.
Both files and tests properties support glob patterns, so you can use wildcards, etc. to avoid specifying each and every file.
File object
Both files and tests property elements can either be a string representing a file name/name pattern, or an object that defines additional properties.
def configure():
return {
'files': [
'src/**/*.py',
# is the same as
{'pattern': 'src/**/*.py', 'instrument': True, 'ignore': False},
],
'tests': ['tests/**/test_*.py'],
}
Pattern
The pattern string property represents the file name or pattern. Each file is checked against patterns from the top of the list to the bottom. If a file satisfies multiple patterns, the first file configuration (from the top of the list) with a matching pattern will be used for the file. The rule applies to all file configuration properties, except the ignore property - if a file pattern is marked as ignored, it will be ignored regardless of its position in the files/tests list.
Ignore
The ignore boolean property (false by default) is used to completely exclude the file from being processed by Wallaby. The setting may be useful for adjusting some broader patterns. Note that if you’d like to ignore a file, you can also just add an exclamation mark as the first character of the path to negate the ignore property (which is false by default). For example, if your tests are in the same folder as your source files, your config may look as follows:
def configure():
return {
'files': ['src/**/*.py', '!src/**/test_*.py'],
'tests': ['src/**/test_*.py'],
}
Instrument
The instrument boolean property (true by default) determines whether the file is instrumented. Setting the property to false stops the file from being compiled, disables file code coverage reporting, and prevents file changes from triggering automatic test execution. The setting should normally be set to false for libraries, utils and other rarely changing files. Using the setting makes Wallaby run your code faster, as it doesn’t have to perform unnecessary work.
def configure():
return {
'files': [
{'pattern': 'libs/utils.py', 'instrument': False},
],
}
Sometimes you may just need to exclude a file from code coverage calculation, or disable code coverage for certain functions, statements or logical branches.
Binary
The binary boolean property (false by default) tells wallaby whether the file is binary (this affects how the file gets copied to wallaby cache). While in most cases wallaby is able to figure it out automatically, the flag can be useful when your binary file extension is not a well-known binary file extension, like images or archives.
def configure():
return {
'files': [
{'pattern': 'data/**/*.myBinaryExt', 'binary': True},
],
}
hideFromErrorStackTrace
The hideFromErrorStackTrace boolean property (false by default) tells wallaby whether the file should be displayed in error stack traces reported by the tool.
Dotfiles and hidden folders (prefixed with dot)
By default, Wallaby’s glob matcher doesn’t allow patterns to match filenames starting with a period. To allow such pattern matching you may use the dot: true setting in your Wallaby config:
def configure():
return {
'dot': True,
}
Example
To sum it up, the configuration sample below makes Wallaby track all .py files in the src folder and all its subfolders recursively, excluding any files whose name ends with _generated; and include but avoid instrumenting helper utilities. The sample also includes all test files from the tests folder whose name starts with test_.
def configure():
return {
'files': [
'src/**/*.py',
{'pattern': 'src/**/*_generated.py', 'ignore': True},
{'pattern': 'utils/*.py', 'instrument': False},
],
'tests': ['tests/**/test_*.py'],
}