From 24c1fd26e3d5a0bf94eb032aca4754289053ebe6 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 24 Jul 2024 16:15:35 +0300 Subject: [PATCH] Tests: Use `pytest.fixture` --- docs/news.rst | 2 ++ tests/ppu_tu.py | 11 +++++------ tests/test_cmp.py | 4 +++- tests/test_remove_old_files.py | 9 +++------ tests/test_rm.py | 4 +++- tests/test_which.py | 4 +++- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index 6841604..742e2f8 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -10,6 +10,8 @@ Version 0.8.1 (in development) * CI(GHActions): Switch to ``setup-miniconda``. +* Tests: Use ``pytest.fixture``. + Version 0.8.0 (2021-09-24) -------------------------- diff --git a/tests/ppu_tu.py b/tests/ppu_tu.py index 94de246..50fe763 100644 --- a/tests/ppu_tu.py +++ b/tests/ppu_tu.py @@ -1,19 +1,18 @@ """PPU test utilities""" - import os import shutil import sys from tempfile import mkdtemp +import pytest + -def setup(): - global tmp_dir +@pytest.fixture(autouse=True) +def tmp_dir(): tmp_dir = mkdtemp() os.chdir(tmp_dir) - - -def teardown(): + yield os.chdir(os.sep) # To the root of the FS shutil.rmtree(tmp_dir, ignore_errors=True) diff --git a/tests/test_cmp.py b/tests/test_cmp.py index a461aac..0e6e499 100755 --- a/tests/test_cmp.py +++ b/tests/test_cmp.py @@ -2,7 +2,9 @@ import subprocess import sys -from ppu_tu import setup, teardown, find_in_path # noqa + +from ppu_tu import find_in_path +from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused test_prog_path = find_in_path('cmp.py') diff --git a/tests/test_remove_old_files.py b/tests/test_remove_old_files.py index 645362a..ec0e56e 100755 --- a/tests/test_remove_old_files.py +++ b/tests/test_remove_old_files.py @@ -4,8 +4,10 @@ from time import time import os import subprocess import sys -from ppu_tu import setup, teardown, find_in_path # noqa + from ppu_tu import create_files, assert_files_exist, assert_files_not_exist +from ppu_tu import find_in_path +from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused test_prog_path = find_in_path('remove-old-files.py') @@ -37,11 +39,6 @@ def test_recursive(): def test_remove_empty_directory(): - teardown() - try: - setup() - except OSError: - pass create_files(['test3', 'test4'], 'subdir') test3 = os.path.join('subdir', 'test3') test4 = os.path.join('subdir', 'test4') diff --git a/tests/test_rm.py b/tests/test_rm.py index 76937e5..a8b0bd9 100755 --- a/tests/test_rm.py +++ b/tests/test_rm.py @@ -2,8 +2,10 @@ import subprocess import sys -from ppu_tu import setup, teardown, find_in_path # noqa + from ppu_tu import create_files, assert_files_exist, assert_files_not_exist +from ppu_tu import find_in_path +from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused test_prog_path = find_in_path('rm.py') diff --git a/tests/test_which.py b/tests/test_which.py index af9886f..052975f 100755 --- a/tests/test_which.py +++ b/tests/test_which.py @@ -3,7 +3,9 @@ import os import subprocess import sys -from ppu_tu import setup, teardown, find_in_path # noqa + +from ppu_tu import find_in_path +from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused test_prog_path = find_in_path('which.py') -- 2.39.5