2010-07-27 03:15:15 +08:00
|
|
|
basic test configuration
|
2009-08-19 01:04:57 +08:00
|
|
|
===================================
|
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
Command line options and configuration file settings
|
|
|
|
-----------------------------------------------------------------
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-07 23:10:22 +08:00
|
|
|
You can get help on options and ini-config values by running::
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
py.test -h # prints options _and_ config file settings
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
This will display command line and configuration file settings
|
|
|
|
which were registered by installed plugins.
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
how test configuration is read from setup/tox ini-files
|
2010-10-28 01:35:27 +08:00
|
|
|
--------------------------------------------------------
|
|
|
|
|
2010-11-07 23:10:22 +08:00
|
|
|
py.test searched for the first matching ini-style configuration file
|
|
|
|
in the directories of command line argument and the directories above.
|
|
|
|
It looks for filenames in this order::
|
|
|
|
|
|
|
|
pytest.ini
|
|
|
|
tox.ini
|
|
|
|
setup.cfg
|
|
|
|
|
|
|
|
Searching stops when the first ``[pytest]`` section is found.
|
|
|
|
There is no merging of configuration values from multiple files. Example::
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
py.test path/to/testdir
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
will look in the following dirs for a config file::
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-07 23:10:22 +08:00
|
|
|
path/to/testdir/pytest.ini
|
2010-11-01 00:41:58 +08:00
|
|
|
path/to/testdir/tox.ini
|
2010-11-07 23:10:22 +08:00
|
|
|
path/to/testdir/setup.cfg
|
|
|
|
path/to/pytest.ini
|
2010-11-01 00:41:58 +08:00
|
|
|
path/to/tox.ini
|
2010-11-07 23:10:22 +08:00
|
|
|
path/to/setup.cfg
|
2010-11-01 00:41:58 +08:00
|
|
|
... # up until root of filesystem
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-07 23:10:22 +08:00
|
|
|
If argument is provided to a py.test run, the current working directory
|
|
|
|
is used to start the search.
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
builtin configuration file options
|
|
|
|
----------------------------------------------
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-06 06:37:25 +08:00
|
|
|
.. confval:: minversion
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-06 06:37:25 +08:00
|
|
|
specifies a minimal pytest version needed for running tests.
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
minversion = 2.1 # will fail if we run with pytest-2.0
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-06 06:37:25 +08:00
|
|
|
.. confval:: addopts
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
add the specified ``OPTS`` to the set of command line arguments as if they
|
|
|
|
had been specified by the user. Example: if you have this ini file content::
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
[pytest]
|
2010-11-01 15:55:14 +08:00
|
|
|
addopts = --maxfail=2 -rf # exit after 2 failures, report fail info
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
issuing ``py.test test_hello.py`` actually means::
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
py.test --maxfail=2 -rf test_hello.py
|
2009-08-19 01:04:57 +08:00
|
|
|
|
2010-11-06 06:37:25 +08:00
|
|
|
Default is to add no options.
|
|
|
|
|
|
|
|
.. confval:: norecursedirs
|
|
|
|
|
|
|
|
Set the directory basename patterns to avoid when recursing
|
2010-11-06 06:37:31 +08:00
|
|
|
for test discovery. The individual (fnmatch-style) patterns are
|
|
|
|
applied to the basename of a directory to decide if to recurse into it.
|
2010-11-06 06:37:25 +08:00
|
|
|
Pattern matching characters::
|
|
|
|
|
|
|
|
* matches everything
|
|
|
|
? matches any single character
|
|
|
|
[seq] matches any character in seq
|
|
|
|
[!seq] matches any char not in seq
|
|
|
|
|
|
|
|
Default patterns are ``.* _* CVS {args}``. Setting a ``norecurse``
|
2010-11-06 06:37:31 +08:00
|
|
|
replaces the default. Here is a customizing example for avoiding
|
2010-11-06 06:37:25 +08:00
|
|
|
a different set of directories::
|
|
|
|
|
|
|
|
# content of setup.cfg
|
|
|
|
[pytest]
|
|
|
|
norecursedirs = .svn _build tmp*
|
|
|
|
|
|
|
|
This would tell py.test to not recurse into typical subversion or
|
|
|
|
sphinx-build directories or into any ``tmp`` prefixed directory.
|
2010-10-14 00:45:07 +08:00
|
|
|
|
2010-11-25 05:01:04 +08:00
|
|
|
.. confval:: python_discovery
|
|
|
|
|
|
|
|
Determines names and patterns for finding Python tests, specified
|
|
|
|
through indendent ``name = value`` settings with these possible names::
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
python_discovery =
|
|
|
|
file = <glob-pattern> <glob-pattern>
|
|
|
|
func = <function-or-method-name-prefix>
|
|
|
|
class = <class-name-prefix>
|
|
|
|
|
|
|
|
See :ref:`change naming conventions` for examples. the ``class``
|
|
|
|
to be empty in which case all non-underscore empty classes
|
|
|
|
will be considered.
|
|
|
|
|