.. _`unittest.TestCase`: unittest.TestCase ã®å¯¾å¿ ======================== .. Support for unittest.TestCase ===================================================================== .. py.test has limited support for running Python `unittest.py style`_ tests. It will automatically collect ``unittest.TestCase`` subclasses and their ``test`` methods in test files. It will invoke ``setUp/tearDown`` methods but also perform py.test's standard ways of treating tests such as IO capturing:: py.test ã¯ãPython ã® `unittest ã¹ã¿ã¤ã«`_ ã®ãã¹ãã«å¶éä»ãã§å¯¾å¿ãã¦ãã¾ãããã¹ããã¡ã¤ã«å ã® ``unittest.TestCase`` ã®ãµãã¯ã©ã¹ã¨ãã® ``test`` ã¡ã½ãããèªåçã«æ¢ãã¾ãã ``setUp/tearDown`` ã¡ã½ãããå®è¡ãã¾ãããIO ãã£ããã£ã®ãããªãã¹ãã®æ±ã㯠pytest ã®æ¨æºçãªæ¹æ³ã§è¡ãã¾ã:: # test_unittest.py ã®å 容 import unittest class MyTest(unittest.TestCase): def setUp(self): print ("hello") # åºåå 容ããã£ãã㣠def test_method(self): x = 1 self.assertEquals(x, 3) .. Running it yields:: ãã®ã³ã¼ããå®è¡ããã¨æ¬¡ã®ããã«ãªãã¾ã:: $ py.test test_unittest.py =========================== test session starts ============================ platform linux2 -- Python 2.7.1 -- pytest-2.2.4 collecting ... collected 1 items test_unittest.py F ================================= FAILURES ================================= ____________________________ MyTest.test_method ____________________________ self = <test_unittest.MyTest testMethod=test_method> def test_method(self): x = 1 > self.assertEquals(x, 3) E AssertionError: 1 != 3 test_unittest.py:8: AssertionError ----------------------------- Captured stdout ------------------------------ hello ========================= 1 failed in 0.01 seconds ========================= .. _`unittest.py style`: http://docs.python.org/library/unittest.html .. _`unittest ã¹ã¿ã¤ã«`: http://docs.python.org/library/unittest.html