@@ -194,13 +194,17 @@ def test_request_post_player_body_nonexistent_response_status_created(client):
194194 """POST /players/ with nonexistent player returns 201 Created with a valid UUID"""
195195 # Arrange
196196 player = nonexistent_player ()
197- # Act
198- response = client .post (PATH , json = player .__dict__ )
199- # Assert
200- assert response .status_code == 201
201- body = response .json ()
202- assert "id" in body
203- assert UUID (body ["id" ]).version == 4 # UUID v4 (API-created)
197+ try :
198+ # Act
199+ response = client .post (PATH , json = player .__dict__ )
200+ # Assert
201+ assert response .status_code == 201
202+ body = response .json ()
203+ assert "id" in body
204+ assert UUID (body ["id" ]).version == 4 # UUID v4 (API-created)
205+ finally :
206+ # Teardown — remove the created player
207+ client .delete (PATH + "squadnumber/" + str (player .squad_number ))
204208
205209
206210# PUT /players/squadnumber/{squad_number} --------------------------------------
@@ -278,11 +282,12 @@ def test_request_delete_player_squadnumber_unknown_response_status_not_found(cli
278282 assert response .status_code == 404
279283
280284
281- def test_request_delete_player_squadnumber_existing_response_status_no_content (client ):
285+ def test_request_delete_player_squadnumber_existing_response_status_no_content (
286+ client , nonexistent_player_in_db
287+ ):
282288 """DELETE /players/squadnumber/{squad_number} with existing number returns 204 No Content"""
283- # Arrange — create the player to be deleted
284- player = nonexistent_player ()
285- client .post (PATH , json = player .__dict__ )
289+ # Arrange
290+ player = nonexistent_player_in_db
286291 # Act
287292 response = client .delete (PATH + "squadnumber/" + str (player .squad_number ))
288293 # Assert
0 commit comments