2016-03-31 17 views
1

Testleri çalıştırmak için django_nose 's NoseTestSuiteRunner kullanıyorum. Şu anda testin docstring'i varsa, test için konsolda (TestCase.ShortDescrption()) basılacak ve testin (TestCase.id()) None adı yazılıyorsa, TestCase.id()TestCase.ShortDescription()'a eklemek istiyorum, böylece TestCase.id() Docstring'in varlığı.Test adı ve modül nasıl eklenir?

örnek testi: yerine

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

sonucu için çok

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() 

Eğer nosetests için --with-id seçeneği vermeniz durumunda İnanıyorum

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 

cevap

0

ben şöyle hem TestCase.__str__ ve TestCase._testMethodDoc dönmek için TestCase.shortDescription() uygulanmasını modifiye:

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() 

yüzden nosetests -v <module-name>.py sonucudur:

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 

Not: Ben katacak Kısa bir süre için bir burun eklentisi.

İlgili konular