.. Doctest integration for modules and test files ========================================================= ã¢ã¸ã¥ã¼ã«ããã¹ããã¡ã¤ã«ã® doctest ==================================== .. By default all files matching the ``test*.txt`` pattern will be run through the python standard ``doctest`` module. You can change the pattern by issuing:: ããã©ã«ã㧠``test*.txt`` ã®ãã¿ã¼ã³ã«ä¸è´ããå ¨ã¦ã®ãã¡ã¤ã«ã¯ãPython æ¨æºã® ``doctest`` ã¢ã¸ã¥ã¼ã«ã§å®è¡ããã¾ãã次ã®ããã«ã³ãã³ãã©ã¤ã³ã§ãã®ãã¿ã¼ã³ãå¤æ´ã§ãã¾ã:: py.test --doctest-glob='*.rst' .. on the command line. You can also trigger running of doctests from docstrings in all python modules (including regular python test modules):: Python ã¢ã¸ã¥ã¼ã« (é常 python ãã¹ãã¢ã¸ã¥ã¼ã«ãå«ã) ã® docstring ããã doctest ãå®è¡ã§ãã¾ã:: py.test --doctest-modules .. You can make these changes permanent in your project by putting them into a pytest.ini file like this:: 次ã®ããã« pytest.ini ã«ãã®è¨å®ã追å ãããã¨ã§ãèªåã®ããã¸ã§ã¯ãã§ãããã£ãå¤æ´ãæ°¸ç¶åã§ãã¾ã:: # pytest.ini ã®å 容 [pytest] addopts = --doctest-modules .. If you then have a text file like this:: 次ã®ãããªããã¹ããã¡ã¤ã«ãåå¨ãã¦:: # example.rst ã®å 容 hello this is a doctest >>> x = 3 >>> x 3 .. and another like this:: ä»ã«ã次ã®ãããªãã¡ã¤ã«ãåå¨ããã¨ãã¾ã:: # mymodule.py ã®å 容 def something(): """ a doctest in a docstring >>> something() 42 """ return 42 .. then you can just invoke ``py.test`` without command line options:: ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ãæå®ãã ``py.test`` ãå®è¡ããã ãã§ã:: $ py.test =========================== test session starts ============================ platform linux2 -- Python 2.7.1 -- pytest-2.2.4 collecting ... collected 1 items mymodule.py . ========================= 1 passed in 0.02 seconds ========================= .. It is possible to use fixtures using the ``getfixture`` helper:: ãã㯠``getfixture`` ãã«ãã¼ã使ã£ã¦ãã£ã¯ã¹ãã£ã使ç¨ãããã¨ãå¯è½ã§ãã:: # content of example.rst >>> tmp = getfixture('tmpdir') >>> ...