Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet58/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   54   55   56   57   58   59   60   61   ...   73
Bog'liq
2 5188215245394412341

Listing 5-1.  test_module01.py
def test_case01():
        assert 'python'.upper() == 'PYTHON'
In Listing 
5-1
, we are importing pytest in the first line. test_case01() is the test 
function. Recall that assert is a Python built-in keyword. Also, just like with nose, we do 
not need to extend these tests from any class. This helps keep the code uncluttered.
Run the test module with the following command:
python3 -m pytest test_module01.py
The output is as follows:
============================ test session starts ====================
platform linux -- Python 3.4.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /home/pi/book/code/chapter05/test, inifile:
collected 1 items
test_module01.py .
========================== 1 passed in 0.05 seconds =================
You can also use verbose mode:
python3 -m pytest -v test_module01.py
The output is as follows:
========================= test session starts ===========================
platform linux -- Python 3.4.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 --  
/usr/bin/python3
cachedir: .cache
rootdir: /home/pi/book/code/chapter05/test, inifile:
collected 1 items
test_module01.py::test_case01 PASSED
======================== 1 passed in 0.04 seconds ====================
www.allitebooks.com


Chapter 5 

 pytest
89
Running Tests with the py.test Command
You can also run these tests with pytest’s own command, called py.test:
py.test test_module01.py
The output is as follows:
======================= test session starts =========================
platform linux -- Python 3.4.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /home/pi/book/code/chapter05/test, inifile:
collected 1 items
test_module01.py .
======================= 1 passed in 0.04 seconds =====================
You can also use verbose mode as follows:
py.test test_module01.py -v
The output in the verbose mode is as follows:
============================ test session starts =======================
platform linux -- Python 3.4.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 --  
/usr/bin/python3
cachedir: .cache
rootdir: /home/pi/book/code/chapter05/test, inifile:
collected 1 items
test_module01.py::test_case01 PASSED
============================ 1 passed in 0.04 seconds =================
For the sake of simplicity and convenience, from now onward, we will use the same 
method to run these tests for rest of the chapter and book. We will use pytest in the next 
chapter to implement test-driven development. Also, observe when you run your own 
tests that the output of test execution is in color by default, although the book shows the 
results in black and white. You do not have to use any external or third-party plugin for 
this effect. Figure 
5-1
 shows a screenshot of an execution sample.


Chapter 5 

 pytest
90
Test Class and Test Package in pytest
Like all the previous test automation frameworks, in pytest you can create test classes 
and test packages. Take a look at the code in Listing 
5-2
 as an example.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   54   55   56   57   58   59   60   61   ...   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