From 79d788ac2319b36c240ff5bf003711186f043569 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 2 Apr 2024 15:58:30 +0200 Subject: [PATCH] tests: use `tmp_path` fixture in `test_curl_source.py` Tiny tweak to remove some boilerplate related to tmpfile handling. The pytest `tmp_path` fixture gives us the tmpdir without having to worry about cleanup etc (and in a slightly more concise way). --- sources/test/test_curl_source.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sources/test/test_curl_source.py b/sources/test/test_curl_source.py index 6fd728f7..409a4d36 100644 --- a/sources/test/test_curl_source.py +++ b/sources/test/test_curl_source.py @@ -2,32 +2,28 @@ import contextlib import os -import pathlib -import tempfile import pytest SOURCES_NAME = "org.osbuild.curl" -def test_curl_source_not_exists(sources_service): - tmpdir = tempfile.TemporaryDirectory() - sources_service.cache = tmpdir.name +def test_curl_source_not_exists(tmp_path, sources_service): desc = { "url": "http://localhost:80/a", } checksum = "sha256:1111111111111111111111111111111111111111111111111111111111111111" + sources_service.cache = tmp_path assert not sources_service.exists(checksum, desc) -def test_curl_source_exists(sources_service): - tmpdir = tempfile.TemporaryDirectory() - sources_service.cache = tmpdir.name +def test_curl_source_exists(tmp_path, sources_service): desc = { "url": "http://localhost:80/a", } checksum = "sha256:1111111111111111111111111111111111111111111111111111111111111111" - pathlib.Path(os.path.join(tmpdir.name, checksum)).touch() + sources_service.cache = tmp_path + (sources_service.cache / checksum).touch() assert sources_service.exists(checksum, desc)