2011-09-06 17:43:42 +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
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
You can get help on command line options and values in INI-style
|
|
|
|
configurations files by using the general help option::
|
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
|
|
|
|
2012-11-06 21:09:12 +08:00
|
|
|
.. _inifiles:
|
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
How test configuration is read from configuration INI-files
|
|
|
|
-------------------------------------------------------------
|
2010-11-25 19:11:10 +08:00
|
|
|
|
2014-01-18 19:31:33 +08:00
|
|
|
``pytest`` searches for the first matching ini-style configuration file
|
2010-11-07 23:10:22 +08:00
|
|
|
in the directories of command line argument and the directories above.
|
2011-03-04 06:40:38 +08:00
|
|
|
It looks for file basenames in this order::
|
2010-11-07 23:10:22 +08:00
|
|
|
|
|
|
|
pytest.ini
|
|
|
|
tox.ini
|
|
|
|
setup.cfg
|
|
|
|
|
2012-06-17 16:59:30 +08:00
|
|
|
Searching stops when the first ``[pytest]`` section is found in any of
|
2014-01-18 19:31:33 +08:00
|
|
|
these files. 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
|
|
|
|
2014-01-18 19:31:33 +08:00
|
|
|
If argument is provided to a ``pytest`` run, the current working directory
|
2010-11-07 23:10:22 +08:00
|
|
|
is used to start the search.
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2010-11-25 19:11:10 +08:00
|
|
|
.. _`how to change command line options defaults`:
|
|
|
|
.. _`adding default options`:
|
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
How to change command line options defaults
|
2010-11-25 19:11:10 +08:00
|
|
|
------------------------------------------------
|
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
It can be tedious to type the same series of command line options
|
2014-01-18 19:31:33 +08:00
|
|
|
every time you use ``pytest``. For example, if you always want to see
|
2011-03-04 06:40:38 +08:00
|
|
|
detailed info on skipped and xfailed tests, as well as have terser "dot"
|
|
|
|
progress output, you can write it into a configuration file::
|
2010-11-25 19:11:10 +08:00
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
# (or tox.ini or setup.cfg)
|
|
|
|
[pytest]
|
|
|
|
addopts = -rsxX -q
|
|
|
|
|
2014-01-18 19:31:33 +08:00
|
|
|
From now on, running ``pytest`` will add the specified options.
|
2010-11-25 19:11:10 +08:00
|
|
|
|
2011-09-06 17:43:42 +08:00
|
|
|
Builtin configuration file options
|
2010-11-01 00:41:58 +08:00
|
|
|
----------------------------------------------
|
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
|
|
|
|
2011-12-05 18:10:48 +08:00
|
|
|
Specifies a minimal pytest version required 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
|
|
|
|
2011-12-05 18:10:48 +08:00
|
|
|
Add the specified ``OPTS`` to the set of command line arguments as if they
|
2010-11-01 00:41:58 +08:00
|
|
|
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
|
|
|
|
|
2014-07-03 22:36:07 +08:00
|
|
|
Default patterns are ``'.*', 'CVS', '_darcs', '{arch}'``. Setting a ``norecursedirs``
|
2011-03-04 06:40:38 +08:00
|
|
|
replaces the default. Here is an example of how to avoid
|
|
|
|
certain directories::
|
2010-11-06 06:37:25 +08:00
|
|
|
|
|
|
|
# content of setup.cfg
|
|
|
|
[pytest]
|
|
|
|
norecursedirs = .svn _build tmp*
|
|
|
|
|
2014-01-18 19:31:33 +08:00
|
|
|
This would tell ``pytest`` to not look into typical subversion or
|
2010-11-06 06:37:25 +08:00
|
|
|
sphinx-build directories or into any ``tmp`` prefixed directory.
|
2010-10-14 00:45:07 +08:00
|
|
|
|
2010-11-25 19:11:10 +08:00
|
|
|
.. confval:: python_files
|
|
|
|
|
|
|
|
One or more Glob-style file patterns determining which python files
|
|
|
|
are considered as test modules.
|
|
|
|
|
|
|
|
.. confval:: python_classes
|
|
|
|
|
|
|
|
One or more name prefixes determining which test classes
|
|
|
|
are considered as test modules.
|
2010-11-25 05:01:04 +08:00
|
|
|
|
2010-11-25 19:11:10 +08:00
|
|
|
.. confval:: python_functions
|
2010-11-25 05:01:04 +08:00
|
|
|
|
2010-11-25 19:11:10 +08:00
|
|
|
One or more name prefixes determining which test functions
|
2013-11-22 20:53:43 +08:00
|
|
|
and methods are considered as test modules. Note that this
|
2014-01-18 19:31:33 +08:00
|
|
|
has no effect on methods that live on a ``unittest.TestCase``
|
2013-11-22 20:53:43 +08:00
|
|
|
derived class.
|
2010-11-25 05:01:04 +08:00
|
|
|
|
2010-11-25 19:11:10 +08:00
|
|
|
See :ref:`change naming conventions` for examples.
|