Skip to content

Commit 48d3667

Browse files
committed
tests: use tmpdir fixture to avoid race
This solves failure with pytest 8. ref: https://docs.pytest.org/en/6.2.x/tmpdir.html fixes: c0fec0de#258
1 parent 65a5d09 commit 48d3667

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

tests/test_dotexport.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,10 @@
99
from .helper import with_setup
1010

1111
TESTPATH = dirname(__file__)
12-
GENPATH = join(TESTPATH, "dotexport")
1312
REFPATH = join(TESTPATH, "refdata")
1413

1514

16-
def setup():
17-
if not exists(GENPATH):
18-
makedirs(GENPATH)
19-
20-
21-
def teardown():
22-
if exists(GENPATH):
23-
rmtree(GENPATH)
24-
25-
26-
@with_setup(setup, teardown)
27-
def test_tree1():
15+
def test_tree1(tmpdir):
2816
"""Tree1."""
2917
root = Node("root")
3018
s0 = Node("sub0", parent=root)
@@ -36,12 +24,11 @@ def test_tree1():
3624
s1c = Node("sub1C", parent=s1)
3725
Node(99, parent=s1c)
3826

39-
RenderTreeGraph(root).to_dotfile(join(GENPATH, "tree1.dot"))
40-
assert cmp(join(GENPATH, "tree1.dot"), join(REFPATH, "tree1.dot"))
27+
RenderTreeGraph(root).to_dotfile(join(tmpdir, "tree1.dot"))
28+
assert cmp(join(tmpdir, "tree1.dot"), join(REFPATH, "tree1.dot"))
4129

4230

43-
@with_setup(setup, teardown)
44-
def test_tree2():
31+
def test_tree2(tmpdir):
4532
"""Tree2."""
4633
root = Node("root")
4734
s0 = Node("sub0", parent=root, edge=2)
@@ -67,12 +54,11 @@ def edgeattrfunc(node, child):
6754
edgeattrfunc=edgeattrfunc,
6855
)
6956

70-
r.to_dotfile(join(GENPATH, "tree2.dot"))
71-
assert cmp(join(GENPATH, "tree2.dot"), join(REFPATH, "tree2.dot"))
57+
r.to_dotfile(join(tmpdir, "tree2.dot"))
58+
assert cmp(join(tmpdir, "tree2.dot"), join(REFPATH, "tree2.dot"))
7259

7360

74-
@with_setup(setup, teardown)
75-
def test_tree_png():
61+
def test_tree_png(tmpdir):
7662
"""Tree to png."""
7763
root = Node("root")
7864
s0 = Node("sub0", parent=root)
@@ -84,4 +70,4 @@ def test_tree_png():
8470
s1c = Node("sub1C", parent=s1)
8571
Node("sub1Ca", parent=s1c)
8672

87-
RenderTreeGraph(root).to_picture(join(GENPATH, "tree1.png"))
73+
RenderTreeGraph(root).to_picture(join(tmpdir, "tree1.png"))

0 commit comments

Comments
 (0)