æ¨æºç㪠(Python) ãã¹ãæ¢ç´¢ã®å¤æ´ ================================== .. Changing standard (Python) test discovery =============================================== .. Changing directory recursion ----------------------------------------------------- ãã£ã¬ã¯ããªã®å帰æ¢ç´¢ã®å¤æ´ ---------------------------- .. You can set the :confval:`norecursedirs` option in an ini-file, for example your ``setup.cfg`` in the project root directory:: ini ãã¡ã¤ã«ã§ :confval:`norecursedirs` ãªãã·ã§ã³ãè¨å®ã§ãã¾ããä¾ãã°ãããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã«ãã ``setup.cfg`` ã«è¨å®ãã¾ã:: # setup.cfg ã®å 容 [pytest] norecursedirs = .svn _build tmp* .. This would tell py.test to not recurse into typical subversion or sphinx-build directories or into any ``tmp`` prefixed directory. ããã¯å ¸åç㪠subversion 㨠sphinx ã® build ãã£ã¬ã¯ããªã¨ ``tmp`` ã¨ããæ¥é è¾ããã¤ãã£ã¬ã¯ããªãå帰æ¢ç´¢ããªãè¨å®ã§ãã .. _`change naming conventions`: å½åè¦åã®å¤æ´ -------------- .. Changing naming conventions ----------------------------------------------------- .. You can configure different naming conventions by setting the :confval:`python_files`, :confval:`python_classes` and :confval:`python_functions` configuration options. Example:: :confval:`python_files`, :confval:`python_classes`, :confval:`python_functions` ãªãã·ã§ã³ãè¨å®ãããã¨ã§å¥ã®å½åè¦åã使ããã¨ãã§ãã¾ãããµã³ãã«ãç´¹ä»ãã¾ã:: # setup.cfg ã®å 容 # tox.ini ã¾ã㯠pytest.init ãã¡ã¤ã«ã§ãå®ç¾©ã§ãã [pytest] python_files=check_*.py python_classes=Check python_functions=check .. This would make py.test look for ``check_`` prefixes in Python filenames, ``Check`` prefixes in classes and ``check`` prefixes in functions and classes. For example, if we have:: ãã®è¨å®ã¯ Python ãã¡ã¤ã«åã« ``check_`` ã ã¯ã©ã¹åã« ``Check`` ãé¢æ°åã« ``check`` ã¨ããæ¥é è¾ã py.test ãæ¢ãããã«ãã¾ããä¾ãã°ã次ã®ãããªãã¡ã¤ã«ã§ã:: # check_myapp.py ã®å 容 class CheckMyApp: def check_simple(self): pass def check_complex(self): pass .. then the test collection looks like this:: ãã¹ãã³ã¬ã¯ã·ã§ã³ã¯æ¬¡ã®ããã«ãªãã¾ã:: $ py.test --collectonly =========================== test session starts ============================ platform linux2 -- Python 2.7.1 -- pytest-2.2.4 collecting ... collected 2 items <Module 'check_myapp.py'> <Class 'CheckMyApp'> <Instance '()'> <Function 'check_simple'> <Function 'check_complex'> ============================= in 0.00 seconds ============================= .. Interpreting cmdline arguments as Python packages ----------------------------------------------------- Python ããã±ã¼ã¸ã¨ãã¦ã³ãã³ãã©ã¤ã³å¼æ°ã解é ----------------------------------------------- .. You can use the ``--pyargs`` option to make py.test try interpreting arguments as python package names, deriving their file system path and then running the test. For example if you have unittest2 installed you can type:: py.test ããã¡ã¤ã«ã·ã¹ãã ã®ãã¹ãã Python ããã±ã¼ã¸åã¨ãã¦å¼æ°ã解éããããã« ``--pyargs`` ãªãã·ã§ã³ã使ãã¾ããä¾ãã°ãunittest2 ãã¤ã³ã¹ãã¼ã«æ¸ã¿ãªãã次ã®ããã«æå®ã§ãã¾ã:: py.test --pyargs unittest2.test.test_skipping -q .. which would run the respective test module. Like with other options, through an ini-file and the :confval:`addopts` option you can make this change more permanently:: ããããã®ãã¹ãã¢ã¸ã¥ã¼ã«ãå®è¡ãã¾ãããã®ä»ã®ãªãã·ã§ã³ã¨åæ§ã« ini ãã¡ã¤ã«ã¨ :confval:`addopts` ãªãã·ã§ã³ã«ããããã®å¤æ´ãæ°¸ç¶åã§ãã¾ã:: # pytest.ini ã®å 容 [pytest] addopts = --pyargs .. Now a simple invocation of ``py.test NAME`` will check if NAME exists as an importable package/module and otherwise treat it as a filesystem path. åç´ã« ``py.test NAME`` ãå®è¡ããã¨ãNAME ãã¤ã³ãã¼ãå¯è½ãªããã±ã¼ã¸ï¼ã¢ã¸ã¥ã¼ã«ã¨ãã¦åå¨ãã¦ãããã©ããããã§ãã¯ãã¾ããåå¨ããªãå ´åããã¡ã¤ã«ã·ã¹ãã ä¸ã®ãã¹ã¨ã㦠NAME ãæ±ãã¾ãã .. Finding out what is collected ----------------------------------------------- ã³ã¬ã¯ã·ã§ã³ã®æ¢ç´¢ ------------------ .. You can always peek at the collection tree without running tests like this:: 次ã®ããã«ãã¹ããå®è¡ããã«ã³ã¬ã¯ã·ã§ã³ããªã¼ããã¼ã¯ã§ãã¾ã:: . $ py.test --collectonly pythoncollection.py =========================== test session starts ============================ platform linux2 -- Python 2.7.1 -- pytest-2.2.4 collecting ... collected 3 items <Module 'pythoncollection.py'> <Function 'test_function'> <Class 'TestClass'> <Instance '()'> <Function 'test_method'> <Function 'test_anothermethod'> ============================= in 0.00 seconds =============================