Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet37/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   33   34   35   36   37   38   39   40   ...   73
Bog'liq
2 5188215245394412341

Listing 3-18.  test_module12.py
import sys
import unittest
class TestClass13(unittest.TestCase):
    @unittest.skip("demonstrating unconditional skipping")
    def test_case01(self):
        self.fail("FATAL")
    @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
    def test_case02(self):
        # Windows specific testing code
        pass
    @unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
    def test_case03(self):
        # Linux specific testing code
        pass
When you run the code in Listing 
3-18
 on the Linux platform, the output is as 
follows:
test_case01 (test_module12.TestClass13) ... skipped 'demonstrating 
unconditional skipping'
test_case02 (test_module12.TestClass13) ... skipped 'requires Windows'
test_case03 (test_module12.TestClass13) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.003s
OK (skipped=2)
When you run the code in Listing 
3-18
 on the Windows platform, the output is as 
follows:
test_case01 (test_module12.TestClass13) ... skipped 'demonstrating 
unconditional skipping'


Chapter 3 

 Unittest
59
test_case02 (test_module12.TestClass13) ... ok
test_case03 (test_module12.TestClass13) ... skipped 
'requires Linux'
----------------------------------------------------------------------
Ran 3 tests in 0.003s
OK (skipped=2)
As you can see, the code skips the test cases based on the OS where it runs. This trick 
is very useful for running platform-specific test cases.
You can also skip entire test classes in a test module using the unittest.
skip(reason) decorator.
Exceptions in the Test Case
When an exception is raised in a test case, the test case fails. The code shown in Listing 
3-19
 
will raise an exception explicitly.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   33   34   35   36   37   38   39   40   ...   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