🔐 Automation Testing · Chương 11 · Mục 11.4
Xác nhận fixture auth_token dùng lại được
Thêm test cuối cùng, dùng fixture auth_token ở mục 11.1:
def test_auth_token_dung_lai_duoc_o_cac_test_khac(auth_token):"""Xac nhan fixture auth_token (dung chung ca phien) tra ve 1 chuoi token khong rong."""assert isinstance(auth_token, str) # token phai la kieu chuoiassert len(auth_token) > 0 # token khong duoc rong
Chạy toàn bộ file:
TERMINAL
pytest tests/test_03_auth.py -v
Kết quả:
KẾT QUẢ
tests/test_03_auth.py::test_auth_01_dung_username_va_password PASSEDtests/test_03_auth.py::test_auth_02_sai_password PASSEDtests/test_03_auth.py::test_auth_03_sai_username PASSEDtests/test_03_auth.py::test_auth_04_thieu_password PASSEDtests/test_03_auth.py::test_auth_05_thieu_username PASSEDtests/test_03_auth.py::test_auth_token_dung_lai_duoc_o_cac_test_khac PASSED============================== 6 passed in 2.64s ==============================
Đến đây, bạn đã hoàn thành Checkpoint 4 — khớp với commit 3991013 trên GitHub.
Chương sau: viết bộ test CRUD đầy đủ cho /booking — sẽ phát hiện 2 hành vi thật thú vị của API khi gọi thử trước khi viết test.