次のHow to run specific test in Nose2 をunittest.TestCase
使用するサブクラスに含まれる単一のテストを実行したいのですが、うまくいかないようです。という名前の次のサンプル スクリプトを使用しています。nose2
mickey_mouse_test.py
import unittest
class TestMickeyMouse(unittest.TestCase):
def test_1plus1is2(self):
self.assertTrue(1+1 == 2)
def test_to_uppercase(self):
self.assertEqual("hello".upper(), "HELLO")
if __name__ == "__main__":
unittest.main()
nose2 mickey_mouse_test
同じディレクトリで実行すると、モジュール内のすべてのテストが実行されます。
kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
ただし、同じtest_to_uppercase
ように実行しようとすると、エラーが発生します。
kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
AttributeError: module 'mickey_mouse_test' has no attribute 'test_to_uppercase'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
オプションを使用すると-s
、別のエラーではありますが、まだエラーが発生します。
kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 -s mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
OSError: /home/kurt/Documents/Scratch/mickey_mouse_test.test_to_uppercase is not a directory
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
また、 http://nose2.readthedocs.io/en/latest/usage.htmlの「実行するテストの指定」セクションを読んでみました 、「Pythonオブジェクト部分」は「ドット付き」である必要があると述べられています名前'。mickey_mouse_test.test_to_uppercase
この場合、なぜ「ドット付きの名前」ではないのかわかりません。これが機能しない理由はありますか?