.. _`pytest helpers`: Pytest çµã¿è¾¼ã¿ãã«ãã¼æ©è½ =========================== .. Pytest builtin helpers ================================================ .. builtin pytest.* functions and helping objects ----------------------------------------------------- çµã¿è¾¼ã¿ã® pytest.* é¢æ°ã¨ãã«ãã¼ãªãã¸ã§ã¯ã ---------------------------------------------- .. You can always use an interactive Python prompt and type:: Python ã¤ã³ã¿ã¼ããªã¿ã¼ã®å¯¾è©±ã¢ã¼ããã次ã®ããã«å ¥åããã¨:: import pytest help(pytest) .. to get an overview on the globally available helpers. ã°ãã¼ãã«ã«å©ç¨ã§ãããã«ãã¼æ©è½ã®æ¦è¦ãææ¡ã§ãã¾ãã .. automodule:: pytest :members: .. _builtinfuncargs: çµã¿è¾¼ã¿é¢æ°ã®å¼æ° ------------------ .. Builtin function arguments ----------------------------------------------------- .. You can ask for available builtin or project-custom :ref:`function arguments <funcargs>` by typing:: 次ã®ããã«å ¥åãã¦ãå©ç¨ã§ããçµã¿è¾¼ã¿ã¾ãã¯ããã¸ã§ã¯ãã«ã¹ã¿ã ã® :ref:`é¢æ°ã®å¼æ° <funcargs>` ã確èªã§ãã¾ãã | $ py.test --fixtures | ====================== test session starts ======================= | platform linux2 -- Python 2.7.1 -- pytest-2.2.4 | collected 0 items | pytestconfig | pytest ã® config ãªãã¸ã§ã¯ãã¨ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ã¸ã®ã¢ã¯ã»ã¹ | | capsys | sys.stdout/sys.stderr ã¸ã®æ¸ãè¾¼ã¿å 容ãåå¾ã§ãã | ãã£ããã£ããåºåå 容㯠``(out, err)`` ã®ã¿ãã«ãè¿ã | ``capsys.readouterr()`` ã¡ã½ããã§å©ç¨ã§ãã | | capfd | ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ 1 㨠2 ã¸æ¸ãè¾¼ã¿å 容ãåå¾ã§ãã | ãã£ããã£ããåºåå 容㯠``(out, err)`` ã®ã¿ãã«ãè¿ã | ``capsys.readouterr()`` ã¡ã½ããã§å©ç¨ã§ãã | | tmpdir | åºæ¬ã¨ãªãä¸æãã£ã¬ã¯ããªé ä¸ã«ãµããã£ã¬ã¯ããªãä½æãã¦ã | ãã¹ãé¢æ°ã®å®è¡æ¯ã«ä¸æãªä¸æãã£ã¬ã¯ããªã®ãªãã¸ã§ã¯ããè¿ã | ãã㯠py.path.local ã®ãã¹ãªãã¸ã§ã¯ããè¿ããã | | monkeypatch | ãªãã¸ã§ã¯ãããã£ã¯ã·ã§ããªãos.environ ãå¤æ´ãã | 次ã®ãã«ãã¼ã¡ã½ãããæä¾ãã ``monkeypatch`` ãªãã¸ã§ã¯ããè¿ããã | | 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) | monkeypatch.chdir(path) | | å ¨ã¦ã®å¤æ´ã¯ãã¹ãé¢æ°ã®å¼ã³åºããçµãã£ãå¾ã§å ã«æ»ãã¾ã | ``raising`` ãã©ã¡ã¼ã¿ã¼ã¯ãã»ããï¼åé¤ã®æä½å¯¾è±¡ããªãã¨ãã« | KeyError ã AttributeError ãçºçããããã©ããã決ãã¾ã | | recwarn | 次ã®ã¡ã½ãããæä¾ãã WarningsRecorder ã¤ã³ã¹ã¿ã³ã¹ãè¿ã | | * ``pop(category=None)``: category ã«ä¸è´ããæå¾ã®è¦åãè¿ã | * ``clear()``: è¦åã®ãªã¹ããåé¤ãã | | è¦åã«ã¤ãã¦ã¯ http://docs.python.org/library/warnings.html ã | åç §ãã¦ãã ãã | | ======================== in 0.00 seconds ======================== .. $ py.test --fixtures =========================== test session starts ============================ platform linux2 -- Python 2.7.1 -- pytest-2.2.4 collected 0 items pytestconfig the pytest config object with access to command line opts. capsys 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. capfd 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. tmpdir return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary directory. The returned object is a `py.path.local`_ path object. monkeypatch The returned ``monkeypatch`` funcarg provides these helper methods to modify objects, dictionaries or os.environ:: 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) monkeypatch.chdir(path) All modifications will be undone after the requesting test function has finished. The ``raising`` parameter determines if a KeyError or AttributeError will be raised if the set/deletion operation has no target. recwarn Return a WarningsRecorder instance that provides these methods: * ``pop(category=None)``: return last warning matching the category. * ``clear()``: clear list of warnings See http://docs.python.org/library/warnings.html for information on warning categories. ============================= in 0.00 seconds =============================