Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet21/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   17   18   19   20   21   22   23   24   ...   73
Bog'liq
2 5188215245394412341

Listing 3-2.  test_module02.py
import unittest
import inspect
class TestClass02(unittest.TestCase):
        def test_case02(self):
                print("\nRunning Test Method : " + inspect.stack()[0][3])
        def test_case01(self):
                print("\nRunning Test Method : " + inspect.stack()[0][3])
if __name__ == '__main__':
        unittest.main(verbosity=2)
In the code in Listing 
3-2
, inspect.stack()[0][3] method prints the name of the 
current test method. It’s useful for debugging when you want to know the order that the 
methods are executed in the test class. The output of the code in Listing 
3-2
 is as follows:
test_case01 (__main__.TestClass02) ...
Running Test Method : test_case01
ok
test_case02 (__main__.TestClass02) ...
Running Test Method : test_case02
ok
----------------------------------------------------------------------
Ran 2 tests in 0.090s
OK
Note that the test methods ran in alphabetical order, irrespective of the order of the 
test methods in the code.


Chapter 3 

 Unittest
35
Verbosity Control
In earlier examples, you controlled the verbosity of test execution through the command 
while invoking the Python test script in the OS console. Now, you will learn how to control 
the verbose mode from the code itself. See the code in Listing 
3-3
 for an example.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   17   18   19   20   21   22   23   24   ...   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