Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet51/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   47   48   49   50   51   52   53   54   ...   73
Bog'liq
2 5188215245394412341

Listing 4-9.  test_module07.py
from nose.tools import raises
@raises(TypeError, ValueError)
def test_case01():
    raise TypeError("This test passes")
@raises(Exception)
def test_case02():
    pass


Chapter 4 

 nose and nose2
79
The output is as follows:
In setUpPackage()...
test.test_module07.test_case01 ... ok
test.test_module07.test_case02 ... FAIL
In tearDownPackage()...
======================================================================
FAIL: test.test_module07.test_case02
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in 
runTest
    self.test(*self.arg)
  File "/usr/local/lib/python3.4/dist-packages/nose/tools/nontrivial.py", 
line 67, in newfunc
    raise AssertionError(message)
AssertionError: test_case02() did not raise Exception
----------------------------------------------------------------------
Ran 2 tests in 0.012s
FAILED (failures=1)
As you can see, test_case02() fails as it does not raise a exception when it is 
supposed to. You can cleverly use this to write negative test cases.
The @timed() decorator
If you are using a timed decorator with the test, then the test must finish within the time 
mentioned in the @timed() decorator to pass. The code in Listing 
4-10
 demonstrates that idea.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   47   48   49   50   51   52   53   54   ...   73




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish