62 lines
1.4 KiB
Plaintext
62 lines
1.4 KiB
Plaintext
|
|
|
|
Learning by examples
|
|
------------------------
|
|
|
|
XXX
|
|
|
|
adding custom options
|
|
+++++++++++++++++++++++
|
|
|
|
py.test supports adding of standard optparse_ Options.
|
|
A plugin may implement the ``addoption`` hook for registering
|
|
custom options::
|
|
|
|
class ConftestPlugin:
|
|
def pytest_addoption(self, parser):
|
|
parser.addoption("-M", "--myopt", action="store",
|
|
help="specify string to set myopt")
|
|
|
|
def pytest_configure(self, config):
|
|
if config.option.myopt:
|
|
# do action based on option value
|
|
|
|
.. _optparse: http://docs.python.org/library/optparse.html
|
|
|
|
Setting default values for test options
|
|
-----------------------------------------
|
|
|
|
You can see all available command line options by running::
|
|
|
|
py.test -h
|
|
|
|
py.test will lookup values of options in this order:
|
|
|
|
* option value supplied at command line
|
|
* content of environment variable ``PYTEST_OPTION_NAME=...``
|
|
* ``name = ...`` setting in the nearest ``conftest.py`` file.
|
|
|
|
The name of an option usually is the one you find
|
|
in the longform of the option, i.e. the name
|
|
behind the ``--`` double-dash.
|
|
|
|
IOW, you can set default values for options per project, per
|
|
home-directoray, per shell session or per test-run.
|
|
|
|
|
|
|
|
Plugin methods
|
|
----------------------------------
|
|
|
|
A Plugin class may implement the following attributes and methods:
|
|
|
|
XXX
|
|
|
|
_`pytest event`:
|
|
|
|
Pytest Events
|
|
-------------------
|
|
|
|
XXX
|
|
|