]> git.phdru.name Git - ppu.git/commitdiff
Tests: Use `pytest.fixture`
authorOleg Broytman <phd@phdru.name>
Wed, 24 Jul 2024 13:15:35 +0000 (16:15 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 24 Jul 2024 14:45:06 +0000 (17:45 +0300)
docs/news.rst
tests/ppu_tu.py
tests/test_cmp.py
tests/test_remove_old_files.py
tests/test_rm.py
tests/test_which.py

index 684160450c8d1c317be08dfab4ee8a7cefc3051e..742e2f884e4499a2a59fa6d2de98b6e135365230 100644 (file)
@@ -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)
 --------------------------
 
index 94de246c490c64bcf09da304e1cb6c8f9095f62c..50fe763a32a88cf513ac1d83f6519758c94a16f2 100644 (file)
@@ -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)
 
index a461aac97799c2899e8a1fe473e3c11ec4c6922f..0e6e499425a7a5f0ded3e1a703a5cd88fc0fe512 100755 (executable)
@@ -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')
index 645362a14dbfa2e74f870f0ef5d76c367d99e7fc..ec0e56e10ab5ab648dde03c60afcd9b5e715e7b9 100755 (executable)
@@ -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')
index 76937e516245f8d8633cab4321d341fc6e46c4a6..a8b0bd967a728a186070a7b93aaf6d107c90da49 100755 (executable)
@@ -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')
index af9886f81e68f1f142241b25096115d387914015..052975f6e6e0e787fffc90129d3a54ee98db129b 100755 (executable)
@@ -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')