Merge pull request #868 from nucleogenic/webui-pytest-warn-on-delete-failures

Display a warning when Pytest fixtures fail to delete a file
This commit is contained in:
Daniel Markstedt 2022-09-27 07:52:24 -07:00 committed by GitHub
commit 3ac3abb13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import pytest import pytest
import uuid import uuid
import warnings
CFG_DIR = "/home/pi/.config/rascsi" CFG_DIR = "/home/pi/.config/rascsi"
IMAGES_DIR = "/home/pi/images" IMAGES_DIR = "/home/pi/images"
@ -37,7 +38,11 @@ def create_test_image(request, http_client):
def delete(): def delete():
for image in images: for image in images:
http_client.post("/files/delete", data={"file_name": image}) response = http_client.post("/files/delete", data={"file_name": image})
if response.status_code != 200 or response.json()["status"] != STATUS_SUCCESS:
warnings.warn(
f"Failed to auto-delete file created with create_test_image fixture: {image}"
)
request.addfinalizer(delete) request.addfinalizer(delete)
return create return create
@ -62,7 +67,9 @@ def list_attached_images(http_client):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def delete_file(http_client): def delete_file(http_client):
def delete(file_name): def delete(file_name):
http_client.post("/files/delete", data={"file_name": file_name}) response = http_client.post("/files/delete", data={"file_name": file_name})
if response.status_code != 200 or response.json()["status"] != STATUS_SUCCESS:
warnings.warn(f"Failed to delete file via delete_file fixture: {file_name}")
return delete return delete