Mmaiqai.com
🏗️ Automation Testing · Chương 13 · Mục 13.3

Fixture client

Tệp tests/conftest.py (thêm import ở đầu file và 2 fixture ở cuối):

FILE tests/conftest.py
from utils.api_client import RestfulBookerClient
@pytest.fixture
def client(api_context, auth_token):
"""RestfulBookerClient da gan san token - dung cho test can quyen sua/xoa."""
return RestfulBookerClient(api_context, token=auth_token)
 
 
@pytest.fixture
def client_khong_token(api_context):
"""RestfulBookerClient KHONG co token - dung rieng cho cac test kiem tra tu choi truy cap."""
return RestfulBookerClient(api_context, token=None)

2 fixture này tận dụng luôn api_context/auth_token đã có — đúng ý "fixture dùng lại fixture khác" ở Chương 9.