2016-03-31 20 views
1

私はdjango_noseNoseTestSuiteRunnerを使ってテストを行っています。現在、テストにdocstringがある場合は、テスト用コンソール(TestCase.ShortDescrption())に出力され、Noneのテスト名(TestCase.id())が印刷されている場合は、TestCase.id()TestCase.ShortDescription()に追加して、TestCase.id docstringの存在。テスト名とモジュールを追加して結果のドキュメントをテストする方法は?

サンプルテスト:代わりに

this is a docstring 1 ... ok 
this is a docstring 2 ... Fail 

の結果のためにそう

class Foo(unittest.TestCase): 
     def test_bar_1(self): 
      """ this is docstring 1""" 
      pass 

     def test_bar_2(self): 
      """ this is docstring 2""" 
      self.fail() 

あなたnosetestsに--with-idオプションを指定した場合、私は、私は信じてい

test_bar_1(path.to.test.Foo) this is a docstring 1 ... ok 
test_bar_2(path.to.test.Foo) this is a docstring 2 ... Fail 

答えて

0

Iは、次のようにTestCase.__str__TestCase._testMethodDoc両方を返すためにTestCase.shortDescription()の実装を変更し:

class Foo(unittest.TestCase): 

     def shortDescription(self): 
      doc = self.__str__() +": "+self._testMethodDoc 
      return doc or None 

     def test_bar_1(self): 
      """ this is docstring 1""" 
      pass 

     def test_bar_2(self): 
      """ this is docstring 2""" 
      self.fail() 

のでnosetests -v <module-name>.pyの結果である:

test_bar_1(path.to.test.Foo): this is a docstring 1 ... ok 
test_bar_2(path.to.test.Foo): this is a docstring 2 ... Fail 

注:私が追加されまもなくそれのための鼻のプラグイン。

0

をしたいあなたが可能なコマンドあなたが探しているものを達成する。

http://nose.readthedocs.org/en/latest/plugins/testid.html

+0

これはidによって、私がunittest.TestCase.id()を意味していて、テスト名とパス全体を返すことを意味します。 https://docs.python.org/2/library/unittest.html#unittest.TestCase.id – Mahmor