Skip to content

Commit aa19429

Browse files
committed
Test error and warning propagation with -qq
Mark these as "slow" (because they are)
1 parent 9c3858f commit aa19429

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ xfail_strict = true
124124
filterwarnings = ["error"]
125125
log_cli_level = "info"
126126
testpaths = ["src", "tests"]
127+
markers = [
128+
"slow: marks tests as slow (deselect with `-m 'not slow'`)",
129+
]
127130

128131

129132
[tool.coverage]

tests/test_cli.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Test command line interface."""
22

33
import logging
4+
import subprocess
5+
import sys
46
from pathlib import Path
7+
from textwrap import dedent
58

69
import pytest
710
from click.testing import CliRunner
@@ -54,6 +57,83 @@ def test_no_cache(self, tmp_path_cwd, caplog):
5457
# Check that at least one collected file was logged as "(cached)"
5558
assert "cached" not in "\n".join(caplog.messages)
5659

60+
@pytest.mark.slow
61+
@pytest.mark.parametrize("workers", [1, 2])
62+
def test_fail_on_warning(self, workers, tmp_path_cwd):
63+
source_with_warning = dedent(
64+
'''
65+
def foo(x: str):
66+
"""
67+
Parameters
68+
----------
69+
x : int
70+
"""
71+
'''
72+
)
73+
package = tmp_path_cwd / "src/sample_package"
74+
package.mkdir(parents=True)
75+
init_py = package / "__init__.py"
76+
with init_py.open("x") as io:
77+
io.write(source_with_warning)
78+
79+
result = subprocess.run(
80+
[
81+
sys.executable,
82+
"-m",
83+
"docstub",
84+
"run",
85+
"--quiet",
86+
"--quiet",
87+
"--fail-on-warning",
88+
"--workers",
89+
str(workers),
90+
str(package),
91+
],
92+
check=False,
93+
capture_output=True,
94+
text=True,
95+
)
96+
assert result.returncode == 1
97+
98+
@pytest.mark.slow
99+
@pytest.mark.parametrize("workers", [1, 2])
100+
def test_no_output_exit_code(self, workers, tmp_path_cwd):
101+
faulty_source = dedent(
102+
'''
103+
def foo(x):
104+
"""
105+
Parameters
106+
----------
107+
x : doctype with syntax error
108+
"""
109+
'''
110+
)
111+
package = tmp_path_cwd / "src/sample_package"
112+
package.mkdir(parents=True)
113+
init_py = package / "__init__.py"
114+
with init_py.open("x") as io:
115+
io.write(faulty_source)
116+
117+
result = subprocess.run(
118+
[
119+
sys.executable,
120+
"-m",
121+
"docstub",
122+
"run",
123+
"--quiet",
124+
"--quiet",
125+
"--workers",
126+
str(workers),
127+
str(package),
128+
],
129+
check=False,
130+
capture_output=True,
131+
text=True,
132+
)
133+
assert result.stdout == ""
134+
assert result.stderr == ""
135+
assert result.returncode == 1
136+
57137

58138
class Test_clean:
59139
@pytest.mark.parametrize("verbosity", [["-v"], ["--verbose"], []])

0 commit comments

Comments
 (0)