The nose testing suite applies introspection to asserts.
Tuttavia, AFAICT, si deve chiamare il loro afferma per ottenere l'introspezione:
import nose
def test1():
nose.tools.assert_equal(6, 5+2)
risultati in
C:\temp\py>C:\Python26\Scripts\nosetests.exe -d test.py
F
======================================================================
FAIL: test.test1
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\nose-0.11.1-py2.6.egg\nose\case.py", line
183, in runTest
self.test(*self.arg)
File "C:\temp\py\test.py", line 3, in test1
nose.tools.assert_equal(6, 5+2)
AssertionError: 6 != 7
>> raise self.failureException, \
(None or '%r != %r' % (6, 7))
Avviso del AssertionError lì. Quando la mia linea era appena assert 6 == 5+2
, vorrei avere:
C:\temp\py>C:\Python26\Scripts\nosetests.exe -d test.py
F
======================================================================
FAIL: test.test1
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\nose-0.11.1-py2.6.egg\nose\case.py", line
183, in runTest
self.test(*self.arg)
File "C:\temp\py\test.py", line 2, in test1
assert 6 == 5 + 2
AssertionError:
>> assert 6 == 5 + 2
Inoltre, non sono sicuro se il loro sbrigativo afferma vengono saltati con -O
, ma sarebbe un rapido controllo.
fonte
2009-08-20 21:09:49
Naturalmente, sapevo che questo. Non voglio scriverne uno in quanto è codificato nell'espressione che viene asserita. ASCIUTTO. –
Capisco cosa intendi. Non credo che Python abbia un modo per farlo. –