Skip to content

Commit 8bd2052

Browse files
committed
Rearrange tests.
1 parent 87954fb commit 8bd2052

File tree

5 files changed

+35
-96
lines changed

5 files changed

+35
-96
lines changed

formate.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use_parentheses = true
3232
remove_redundant_aliases = true
3333
default_section = "THIRDPARTY"
3434
known_third_party = [
35+
"backports_entry_points_selectable",
3536
"coincidence",
3637
"coverage",
3738
"coverage_pyver_pragma",

repo_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version: '0.1.0'
1010
license: 'MIT'
1111
short_desc: '(experimental) Allows hooks to be defined which are called when recreating a tox testenv.'
1212

13-
min_coverage: 90
13+
min_coverage: 100
1414
use_whey: true
1515
enable_conda: False
1616
sphinx_html_theme: furo

tests/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
git+https://github.com/python-coincidence/testing-tox
2+
backports-entry-points-selectable>=1.0.2
13
coincidence>=0.2.0
24
coverage>=5.1
35
coverage-pyver-pragma>=0.2.1
4-
domdf-python-tools[testing]>=2.0.1
5-
iniconfig!=1.1.0,>=1.0.1
66
pytest>=6.0.0
77
pytest-cov>=2.8.1
8-
pytest-randomly>=3.3.1
8+
pytest-randomly>=3.6.0
99
pytest-timeout>=1.4.2

tests/test_hooks.py

Lines changed: 29 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
1-
# stdlib
2-
import sys
3-
41
# 3rd party
52
import pytest
6-
import tox # type: ignore
7-
import tox.reporter # type: ignore
83
from coincidence.selectors import not_pypy
9-
from domdf_python_tools.paths import in_directory
10-
4+
from testing_tox import run_tox
115

12-
def test_rmdir_docs(tmp_pathplus, capsys):
13-
tox.reporter._INSTANCE.tw._file = sys.stdout
146

7+
@pytest.fixture()
8+
def basic_docs_testenv(tmp_pathplus):
159
build_dir = tmp_pathplus / "doc-source" / "build"
16-
1710
build_dir.mkdir(parents=True)
1811

1912
(tmp_pathplus / "tox.ini").write_lines([
2013
"[testenv:docs]",
2114
"deps = sphinx",
2215
"skip_install = True",
2316
"commands = sphinx-build --version",
24-
'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")',
2517
])
2618

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

21+
22+
def test_rmdir_docs(basic_docs_testenv, tmp_pathplus, capsys):
23+
with (tmp_pathplus / "tox.ini").open('a') as fp:
24+
fp.write('recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")\n')
25+
26+
try:
27+
run_tox(["-e", "docs", "-r"], tmp_pathplus)
3128
finally:
3229
stdout = capsys.readouterr().out
3330
print(stdout)
3431

3532
assert (tmp_pathplus / "doc-source").is_dir()
36-
assert not build_dir.is_dir()
33+
assert not basic_docs_testenv.is_dir()
3734

38-
assert f"docs recreate hook: removing {build_dir}" in stdout
35+
assert f"docs recreate hook: removing {basic_docs_testenv}" in stdout
3936

4037

4138
@not_pypy("mypy does noy support PyPy")
4239
def test_rmdir_mypy(tmp_pathplus, capsys):
43-
tox.reporter._INSTANCE.tw._file = sys.stdout
4440

4541
cache_dir = tmp_pathplus / ".mypy_cache"
46-
4742
cache_dir.mkdir()
4843

4944
(tmp_pathplus / "tox.ini").write_lines([
@@ -55,127 +50,70 @@ def test_rmdir_mypy(tmp_pathplus, capsys):
5550
])
5651

5752
try:
58-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
59-
tox.cmdline(["-e", "mypy", "-r"])
60-
53+
run_tox(["-e", "mypy", "-r"], tmp_pathplus)
6154
finally:
6255
stdout = capsys.readouterr().out
6356
print(stdout)
6457

65-
stdout = capsys.readouterr().out
66-
print(stdout)
67-
6858
assert not cache_dir.is_dir()
6959

7060
assert f"mypy recreate hook: removing {cache_dir}" in stdout
7161

7262

73-
def test_simple_custom_hook(tmp_pathplus, capsys):
74-
tox.reporter._INSTANCE.tw._file = sys.stdout
75-
76-
(tmp_pathplus / "tox.ini").write_lines([
77-
"[testenv:docs]",
78-
"deps = sphinx",
79-
"skip_install = True",
80-
"commands = sphinx-build --version",
81-
'recreate_hook = "hello world"',
82-
])
63+
def test_simple_custom_hook(basic_docs_testenv, tmp_pathplus, capsys):
64+
with (tmp_pathplus / "tox.ini").open('a') as fp:
65+
fp.write('recreate_hook = "hello world"')
8366

8467
try:
85-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
86-
tox.cmdline(["-e", "docs", "-r"])
87-
68+
run_tox(["-e", "docs", "-r"], tmp_pathplus)
8869
finally:
8970
stdout = capsys.readouterr().out
9071
print(stdout)
9172

92-
stdout = capsys.readouterr().out
93-
print(stdout)
94-
9573
assert f"docs recreate hook: hello world" in stdout
9674

9775

98-
def test_custom_hook(tmp_pathplus, capsys):
99-
tox.reporter._INSTANCE.tw._file = sys.stdout
100-
101-
(tmp_pathplus / "tox.ini").write_lines([
102-
"[testenv:docs]",
103-
"deps = sphinx",
104-
"skip_install = True",
105-
"commands = sphinx-build --version",
106-
"recreate_hook = custom_hook.custom_hook()",
107-
])
76+
def test_custom_hook(basic_docs_testenv, tmp_pathplus, capsys):
77+
with (tmp_pathplus / "tox.ini").open('a') as fp:
78+
fp.write('recreate_hook = custom_hook.custom_hook()\n')
10879

10980
(tmp_pathplus / "custom_hook.py").write_lines([
11081
"def custom_hook() -> str:",
11182
'\treturn "this is a custom hook"',
11283
])
11384

11485
try:
115-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
116-
tox.cmdline(["-e", "docs", "-r"])
117-
86+
run_tox(["-e", "docs", "-r"], tmp_pathplus)
11887
finally:
11988
stdout = capsys.readouterr().out
12089
print(stdout)
12190

122-
stdout = capsys.readouterr().out
123-
print(stdout)
124-
12591
assert f"docs recreate hook: this is a custom hook" in stdout
12692

12793

128-
def test_no_hook(tmp_pathplus, capsys):
129-
tox.reporter._INSTANCE.tw._file = sys.stdout
130-
131-
(tmp_pathplus / "tox.ini").write_lines([
132-
"[testenv:docs]",
133-
"deps = sphinx",
134-
"skip_install = True",
135-
"commands = sphinx-build --version",
136-
])
94+
def test_no_hook(basic_docs_testenv, tmp_pathplus, capsys):
13795

13896
try:
139-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
140-
tox.cmdline(["-e", "docs", "-r"])
97+
run_tox(["-e", "docs", "-r"], tmp_pathplus)
14198

14299
finally:
143100
stdout = capsys.readouterr().out
144101
print(stdout)
145102

146-
stdout = capsys.readouterr().out
147-
print(stdout)
148-
149103
assert "docs recreate hook: " not in stdout
150104

151105

152-
def test_not_recreate(tmp_pathplus, capsys):
153-
tox.reporter._INSTANCE.tw._file = sys.stdout
154-
155-
build_dir = tmp_pathplus / "doc-source" / "build"
156-
157-
build_dir.mkdir(parents=True)
158-
159-
(tmp_pathplus / "tox.ini").write_lines([
160-
"[testenv:docs]",
161-
"deps = sphinx",
162-
"skip_install = True",
163-
"commands = sphinx-build --version",
164-
'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")',
165-
])
106+
def test_not_recreate(basic_docs_testenv, tmp_pathplus, capsys):
107+
with (tmp_pathplus / "tox.ini").open('a') as fp:
108+
fp.write('recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")\n')
166109

167110
try:
168-
with pytest.raises(SystemExit), in_directory(tmp_pathplus):
169-
tox.cmdline(["-e", "docs"])
170-
111+
run_tox(["-e", "docs"], tmp_pathplus)
171112
finally:
172113
stdout = capsys.readouterr().out
173114
print(stdout)
174115

175-
stdout = capsys.readouterr().out
176-
print(stdout)
177-
178116
assert (tmp_pathplus / "doc-source").is_dir()
179-
assert build_dir.is_dir()
117+
assert basic_docs_testenv.is_dir()
180118

181119
assert "docs recreate hook: " not in stdout

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ min_python_version = 3.7
135135
plugins = coverage_pyver_pragma
136136
137137
[coverage:report]
138-
fail_under = 90
138+
fail_under = 100
139139
exclude_lines =
140140
raise AssertionError
141141
raise NotImplementedError

0 commit comments

Comments
 (0)