2010-11-06 06:37:31 +08:00
|
|
|
|
2010-11-18 21:56:16 +08:00
|
|
|
.. _`pytest helpers`:
|
|
|
|
|
2011-09-06 17:43:42 +08:00
|
|
|
Pytest builtin helpers
|
2010-11-06 06:37:31 +08:00
|
|
|
================================================
|
|
|
|
|
2010-11-18 21:56:16 +08:00
|
|
|
builtin pytest.* functions and helping objects
|
2010-11-06 06:37:31 +08:00
|
|
|
-----------------------------------------------------
|
|
|
|
|
|
|
|
You can always use an interactive Python prompt and type::
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
help(pytest)
|
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
to get an overview on the globally available helpers.
|
2010-11-06 06:37:31 +08:00
|
|
|
|
|
|
|
.. automodule:: pytest
|
|
|
|
:members:
|
2010-11-06 06:37:31 +08:00
|
|
|
|
2012-10-07 19:06:17 +08:00
|
|
|
.. _builtinfixtures:
|
|
|
|
.. _builtinfuncargs:
|
2011-10-21 21:45:56 +08:00
|
|
|
|
2012-08-01 20:52:51 +08:00
|
|
|
Builtin resources / function arguments
|
2010-11-06 06:37:31 +08:00
|
|
|
-----------------------------------------------------
|
|
|
|
|
|
|
|
You can ask for available builtin or project-custom
|
2010-11-25 19:11:10 +08:00
|
|
|
:ref:`function arguments <funcargs>` by typing::
|
2010-11-06 06:37:31 +08:00
|
|
|
|
2012-10-05 20:24:44 +08:00
|
|
|
$ py.test --fixtures
|
2011-08-21 00:37:00 +08:00
|
|
|
=========================== test session starts ============================
|
2012-10-07 19:06:17 +08:00
|
|
|
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev19
|
2011-08-21 00:37:00 +08:00
|
|
|
collected 0 items
|
2010-11-06 06:37:31 +08:00
|
|
|
capsys
|
2011-03-04 06:40:38 +08:00
|
|
|
enables capturing of writes to sys.stdout/sys.stderr and makes
|
|
|
|
captured output available via ``capsys.readouterr()`` method calls
|
|
|
|
which return a ``(out, err)`` tuple.
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
capfd
|
2011-03-04 06:40:38 +08:00
|
|
|
enables capturing of writes to file descriptors 1 and 2 and makes
|
|
|
|
captured output available via ``capsys.readouterr()`` method calls
|
|
|
|
which return a ``(out, err)`` tuple.
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
tmpdir
|
|
|
|
return a temporary directory path object
|
2011-03-04 06:40:38 +08:00
|
|
|
which is unique to each test function invocation,
|
2010-11-06 06:37:31 +08:00
|
|
|
created as a sub directory of the base temporary
|
|
|
|
directory. The returned object is a `py.path.local`_
|
|
|
|
path object.
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
monkeypatch
|
|
|
|
The returned ``monkeypatch`` funcarg provides these
|
|
|
|
helper methods to modify objects, dictionaries or os.environ::
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
monkeypatch.setattr(obj, name, value, raising=True)
|
|
|
|
monkeypatch.delattr(obj, name, raising=True)
|
|
|
|
monkeypatch.setitem(mapping, name, value)
|
|
|
|
monkeypatch.delitem(obj, name, raising=True)
|
|
|
|
monkeypatch.setenv(name, value, prepend=False)
|
|
|
|
monkeypatch.delenv(name, value, raising=True)
|
|
|
|
monkeypatch.syspath_prepend(path)
|
2012-02-06 07:33:04 +08:00
|
|
|
monkeypatch.chdir(path)
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
All modifications will be undone after the requesting
|
|
|
|
test function has finished. The ``raising``
|
2010-11-06 06:37:31 +08:00
|
|
|
parameter determines if a KeyError or AttributeError
|
|
|
|
will be raised if the set/deletion operation has no target.
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
recwarn
|
|
|
|
Return a WarningsRecorder instance that provides these methods:
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
* ``pop(category=None)``: return last warning matching the category.
|
|
|
|
* ``clear()``: clear list of warnings
|
2010-11-26 20:26:56 +08:00
|
|
|
|
2011-03-04 06:40:38 +08:00
|
|
|
See http://docs.python.org/library/warnings.html for information
|
|
|
|
on warning categories.
|
|
|
|
|
2011-08-21 00:37:00 +08:00
|
|
|
|
2012-10-07 19:06:17 +08:00
|
|
|
============================= in 0.00 seconds =============================
|