Skip to content

Commit 5fb93dc

Browse files
committed
Use raw string paths in tests.
1 parent 8a53b9a commit 5fb93dc

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

tests/test_hooks.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ def test_rmdir_docs(tmp_pathplus, capsys):
2121
"deps = sphinx",
2222
"skip_install = True",
2323
"commands = sphinx-build --version",
24-
'recreate_hook = builtin.rmdir("{toxinidir}/doc-source/build")',
24+
'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")',
2525
])
2626

27-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
28-
tox.cmdline(["-e", "docs", "-r"])
27+
try:
28+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
29+
tox.cmdline(["-e", "docs", "-r"])
2930

30-
stdout = capsys.readouterr().out
31-
print(stdout)
31+
finally:
32+
stdout = capsys.readouterr().out
33+
print(stdout)
3234

3335
assert (tmp_pathplus / "doc-source").is_dir()
3436
assert not build_dir.is_dir()
@@ -49,11 +51,16 @@ def test_rmdir_mypy(tmp_pathplus, capsys):
4951
"deps = mypy",
5052
"skip_install = True",
5153
"commands = mypy --version",
52-
'recreate_hook = builtin.rmdir("{toxinidir}/.mypy_cache")',
54+
'recreate_hook = builtin.rmdir(r"{toxinidir}/.mypy_cache")',
5355
])
5456

55-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
56-
tox.cmdline(["-e", "mypy", "-r"])
57+
try:
58+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
59+
tox.cmdline(["-e", "mypy", "-r"])
60+
61+
finally:
62+
stdout = capsys.readouterr().out
63+
print(stdout)
5764

5865
stdout = capsys.readouterr().out
5966
print(stdout)
@@ -74,8 +81,13 @@ def test_simple_custom_hook(tmp_pathplus, capsys):
7481
'recreate_hook = "hello world"',
7582
])
7683

77-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
78-
tox.cmdline(["-e", "docs", "-r"])
84+
try:
85+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
86+
tox.cmdline(["-e", "docs", "-r"])
87+
88+
finally:
89+
stdout = capsys.readouterr().out
90+
print(stdout)
7991

8092
stdout = capsys.readouterr().out
8193
print(stdout)
@@ -99,8 +111,13 @@ def test_custom_hook(tmp_pathplus, capsys):
99111
'\treturn "this is a custom hook"',
100112
])
101113

102-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
103-
tox.cmdline(["-e", "docs", "-r"])
114+
try:
115+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
116+
tox.cmdline(["-e", "docs", "-r"])
117+
118+
finally:
119+
stdout = capsys.readouterr().out
120+
print(stdout)
104121

105122
stdout = capsys.readouterr().out
106123
print(stdout)
@@ -118,8 +135,13 @@ def test_no_hook(tmp_pathplus, capsys):
118135
"commands = sphinx-build --version",
119136
])
120137

121-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
122-
tox.cmdline(["-e", "docs", "-r"])
138+
try:
139+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
140+
tox.cmdline(["-e", "docs", "-r"])
141+
142+
finally:
143+
stdout = capsys.readouterr().out
144+
print(stdout)
123145

124146
stdout = capsys.readouterr().out
125147
print(stdout)
@@ -139,11 +161,16 @@ def test_not_recreate(tmp_pathplus, capsys):
139161
"deps = sphinx",
140162
"skip_install = True",
141163
"commands = sphinx-build --version",
142-
'recreate_hook = builtin.rmdir("{toxinidir}/doc-source/build")',
164+
'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")',
143165
])
144166

145-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
146-
tox.cmdline(["-e", "docs"])
167+
try:
168+
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
169+
tox.cmdline(["-e", "docs"])
170+
171+
finally:
172+
stdout = capsys.readouterr().out
173+
print(stdout)
147174

148175
stdout = capsys.readouterr().out
149176
print(stdout)

0 commit comments

Comments
 (0)