Skip to content

Commit aadfb38

Browse files
committed
Tests: Use pytest.fixture
1 parent f49a828 commit aadfb38

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

docs/news.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Version 0.8.1 (in development)
1010

1111
* CI(GHActions): Switch to ``setup-miniconda``.
1212

13+
* Tests: Use ``pytest.fixture``.
14+
1315
Version 0.8.0 (2021-09-24)
1416
--------------------------
1517

tests/ppu_tu.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
"""PPU test utilities"""
22

3-
43
import os
54
import shutil
65
import sys
76
from tempfile import mkdtemp
87

8+
import pytest
9+
910

10-
def setup():
11-
global tmp_dir
11+
@pytest.fixture(autouse=True)
12+
def tmp_dir():
1213
tmp_dir = mkdtemp()
1314
os.chdir(tmp_dir)
14-
15-
16-
def teardown():
15+
yield
1716
os.chdir(os.sep) # To the root of the FS
1817
shutil.rmtree(tmp_dir, ignore_errors=True)
1918

tests/test_cmp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import subprocess
44
import sys
5-
from ppu_tu import setup, teardown, find_in_path # noqa
5+
6+
from ppu_tu import find_in_path
7+
from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused
68

79

810
test_prog_path = find_in_path('cmp.py')

tests/test_remove_old_files.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import os
55
import subprocess
66
import sys
7-
from ppu_tu import setup, teardown, find_in_path # noqa
7+
88
from ppu_tu import create_files, assert_files_exist, assert_files_not_exist
9+
from ppu_tu import find_in_path
10+
from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused
911

1012

1113
test_prog_path = find_in_path('remove-old-files.py')
@@ -37,11 +39,6 @@ def test_recursive():
3739

3840

3941
def test_remove_empty_directory():
40-
teardown()
41-
try:
42-
setup()
43-
except OSError:
44-
pass
4542
create_files(['test3', 'test4'], 'subdir')
4643
test3 = os.path.join('subdir', 'test3')
4744
test4 = os.path.join('subdir', 'test4')

tests/test_rm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import subprocess
44
import sys
5-
from ppu_tu import setup, teardown, find_in_path # noqa
5+
66
from ppu_tu import create_files, assert_files_exist, assert_files_not_exist
7+
from ppu_tu import find_in_path
8+
from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused
79

810

911
test_prog_path = find_in_path('rm.py')

tests/test_which.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import os
44
import subprocess
55
import sys
6-
from ppu_tu import setup, teardown, find_in_path # noqa
6+
7+
from ppu_tu import find_in_path
8+
from ppu_tu import tmp_dir # noqa: F401 tmp_dir imported but unused
79

810

911
test_prog_path = find_in_path('which.py')

0 commit comments

Comments
 (0)