Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet63/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   59   60   61   62   63   64   65   66   ...   73
Bog'liq
2 5188215245394412341

Listing 5-6.  test_module05.py
import pytest
@pytest.fixture()
def fixture01():
    print("\nIn fixture01()...")
@pytest.mark.usefixtures('fixture01')
def test_case01(fixture01):
    print("\nIn test_case01()...")
The output of Listing 
5-6
 is exactly the same as the code in Listing 
5-5
.
You can use the @pytest.mark.usefixtures() decorator for a class, as shown in 
Listing 
5-7
.
Listing 5-7.  test_module06.py
import pytest
@pytest.fixture()
def fixture01():
    print("\nIn fixture01()...")
@pytest.mark.usefixtures('fixture01')
class TestClass03:
    def test_case01(self):
        print("I'm the test_case01")
    def test_case02(self):
        print("I'm the test_case02")
Here is the output:
============================ 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 2 items
test_module06.py::TestClass03::test_case01
In fixture01()...


Chapter 5 

 pytest
95
I'm the test_case01
PASSED
test_module06.py::TestClass03::test_case02
In fixture01()...
I'm the test_case02
PASSED
========================== 2 passed in 0.08 seconds ====================
If you want to run a block of code after the test with a fixture has run, you have to add 
a finalizer function to the fixture. Listing 
5-8
 demonstrates this idea.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   59   60   61   62   63   64   65   66   ...   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