You are on page 1of 1

Pytest Fixtures Handson

Question 1:

import pytest

@pytest.fixture(scope='session')
def fixture_sess():
print("Inside session fixture")

@pytest.fixture(scope='function')
def fixture_func():
print("Inside function fixture")

@pytest.fixture(scope='module')
def fixture_modl():
print("Inside module fixture")

@pytest.fixture(scope='class')
def fixture_clss():
print("Inside class fixture")

class TestOrder:
@pytest.mark.usefixtures('fixture_sess', 'fixture_modl', 'fixture_clss',
'fixture_func')
def test_one(self):
print("Inside test")

import pytest

@pytest.fixture
def create_student():
def _create_student(name):
return {
"name": name,
"grade" : 'A'
}
return _create_student

def test_one(create_student):
o1 = create_student("Ravi")
o2 = create_student("Abdul")
print(o1)
print(o2)

You might also like