This is liable to change in the future.A
python_test()rule is used to define a set of
.pyfiles that contain tests to run via the Python unit testing framework.
The name of the rule.
The set of
.pyfiles included in this library.
Python-platform-specific source files. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched (as defined in the `python#name` section of `.buckconfig`), and the second element is a list of source files.
Static files to be packaged along with the python sources. These resources can be accessed at runtime using the pkg_resources API.
Python-platform-specific resource files. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched (as defined in the `python#name` section of `.buckconfig`), and the second element is a list of resource files.
The package for which the given specified sources and resources should reside in their final location in the top-level binary. If unset, the project relative directory that houses the BUCK file is used.
The main module used to run the tests. This parameter is normally not needed, as Buck will provide a default main module that runs all tests. However, you can override this with your own module to perform custom initialization or command line processing. Your custom module can import the standard Buck test main as
__test_main__, and can invoke it's normal main function as
The name of the Python platform to build against by default (as defined in the `python#name` section of `.buckconfig`).
A map of environment names and values to set when running the test.
It is also possible to expand references to other rules within the values of these environment variables, using builtin string parameter macros:
- Expands to the location of the output of the build rule. This means that you can refer to these without needing to be aware of how Buck is storing data on the disk mid-build.
python_libraryrules used by the tests in this rules sources.
A list of labels to be applied to these tests. These labels are arbitrary text strings and have no meaning within buck itself. They can, however, have meaning for you as a test author (e.g.,
fast). A label can be used to filter or include a specific
python_test()rule when executing
If set specifies the maximum amount of time (in milliseconds) in which all of the tests in this rule should complete. This overrides the default
rule_timeoutif any has been specified in test.rule_timeout.
Used to override the global packaging style set with python.package_style.
A list of C/C++ library dependencies that need to be loaded before any other libraries when the python binary starts up. This requires dynamic loader support found on most systems (e.g. `LD_PRELOAD`).
List of build target patterns that identify the build rules that can include this rule in its
# A rule that includes a single .py file containing tests. python_test( name = 'fileutil_test', srcs = ['fileutil_tests.py'], deps = [ ':fileutil', ], ) # A rule that uses glob() to include all sources in the directory which the # rule is defined. It also lists a resource file that gets packaged with # the sources in this rule. python_library( name = 'fileutil', srcs = glob(['fileutil/**/*.py'], resources = [ 'testdata.dat', ], )
Here is an example of using the `platform_srcs` and `platform_resources` parameters to pull in sources/resources only when building for a specific Python platform:
; .buckconfig [python#py2] interpreter = /usr/bin/python2.7 [python#py3] interpreter = /usr/bin/python3.4
# BUCK python_test( name = 'test', platform_srcs = [ ('py2', ['foo.py']), ('py3', ['bar.py']), ], platform_resources = [ ('py2', ['foo.dat']), ('py3', ['bar.dat']), ], )
Here is an example of using the `platform` parameter to select the "py2" Python platform as defined in `.buckconfig` above:
# BUCK python_test( name = 'bin', platform = 'py2', srcs = [ 'foo.py', ], )