Skip to content

Commit 183646f

Browse files
authored
test: fix unit tests caused by error output being routed to stderr instead of stdout (#668)
1 parent afdc3b2 commit 183646f

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ testunit:
7272
@orig_xdg_config_home=$${XDG_CONFIG_HOME:-}; \
7373
export LINODE_CLI_TEST_MODE=1 XDG_CONFIG_HOME=/tmp/linode/.config; \
7474
pytest -v tests/unit; \
75-
export XDG_CONFIG_HOME=$$orig_xdg_config_home
75+
exit_code=$$?; \
76+
export XDG_CONFIG_HOME=$$orig_xdg_config_home; \
77+
exit $$exit_code
7678

7779
.PHONY: testint
7880
testint:

tests/unit/test_configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_set_user(self):
8080
f = io.StringIO()
8181

8282
with pytest.raises(SystemExit) as err:
83-
with contextlib.redirect_stdout(f):
83+
with contextlib.redirect_stderr(f):
8484
conf.set_user("bad_user")
8585

8686
assert err.value.code == 4
@@ -98,7 +98,7 @@ def test_remove_user(self):
9898
f = io.StringIO()
9999

100100
with pytest.raises(SystemExit) as err:
101-
with contextlib.redirect_stdout(f):
101+
with contextlib.redirect_stderr(f):
102102
conf.remove_user("cli-dev")
103103

104104
assert "default user!" in f.getvalue()
@@ -131,7 +131,7 @@ def test_set_default_user(self):
131131

132132
f = io.StringIO()
133133
with pytest.raises(SystemExit) as err:
134-
with contextlib.redirect_stdout(f):
134+
with contextlib.redirect_stderr(f):
135135
conf.set_default_user("bad_user")
136136

137137
assert err.value.code == 4
@@ -226,7 +226,7 @@ def test_update(self):
226226
]
227227

228228
f = io.StringIO()
229-
with contextlib.redirect_stdout(f):
229+
with contextlib.redirect_stderr(f):
230230
result = vars(conf.update(ns, allowed_defaults))
231231

232232
assert "--no-defaults" in f.getvalue()

tests/unit/test_plugin_image_upload.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_no_file(mock_cli, capsys: CaptureFixture):
2828
PluginContext("REALTOKEN", mock_cli),
2929
)
3030

31-
captured_text = capsys.readouterr().out
31+
captured_text = capsys.readouterr().err
3232

3333
assert err.value.code == 8
3434
assert "No file at blah.txt" in captured_text
@@ -43,7 +43,7 @@ def test_file_too_large(mock_cli, capsys: CaptureFixture):
4343
with pytest.raises(SystemExit) as err:
4444
plugin.call(args, ctx)
4545

46-
captured_text = capsys.readouterr().out
46+
captured_text = capsys.readouterr().err
4747

4848
assert err.value.code == 8
4949
assert "File blah.txt is too large" in captured_text
@@ -61,7 +61,7 @@ def test_unauthorized(mock_cli, capsys: CaptureFixture):
6161
with pytest.raises(SystemExit) as err:
6262
plugin.call(args, ctx)
6363

64-
captured_text = capsys.readouterr().out
64+
captured_text = capsys.readouterr().err
6565

6666
assert err.value.code == 2
6767
assert "Your token was not authorized to use this endpoint" in captured_text
@@ -79,7 +79,7 @@ def test_non_beta(mock_cli, capsys: CaptureFixture):
7979
with pytest.raises(SystemExit) as err:
8080
plugin.call(args, ctx)
8181

82-
captured_text = capsys.readouterr().out
82+
captured_text = capsys.readouterr().err
8383

8484
assert err.value.code == 2
8585
assert (
@@ -99,7 +99,7 @@ def test_non_beta(mock_cli, capsys: CaptureFixture):
9999
with pytest.raises(SystemExit) as err:
100100
plugin.call(args, ctx)
101101

102-
captured_text = capsys.readouterr().out
102+
captured_text = capsys.readouterr().err
103103

104104
assert err.value.code == 2
105105
assert (
@@ -118,7 +118,7 @@ def test_failed_upload(mock_cli, capsys: CaptureFixture):
118118
with pytest.raises(SystemExit) as err:
119119
plugin.call(args, ctx)
120120

121-
captured_text = capsys.readouterr().out
121+
captured_text = capsys.readouterr().err
122122

123123
assert err.value.code == 2
124124
assert (

tests/unit/test_plugin_ssh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_windows_error(capsys: CaptureFixture):
3030

3131
assert err.value.code == 2
3232

33-
captured_text = capsys.readouterr().out
33+
captured_text = capsys.readouterr().err
3434
assert "This plugin is not currently supported in Windows." in captured_text
3535

3636

@@ -54,7 +54,7 @@ def mock_call_operation(*a, filters=None):
5454

5555
assert err.value.code == 2
5656

57-
captured_text = capsys.readouterr().out
57+
captured_text = capsys.readouterr().err
5858
assert (
5959
f"{test_label} is not running (status is provisioning)" in captured_text
6060
)
@@ -163,7 +163,7 @@ def mock_call_operation(*a, filters=None):
163163

164164
assert err.value.code == 2
165165

166-
captured_text = capsys.readouterr().out
166+
captured_text = capsys.readouterr().err
167167

168168
assert "Could not retrieve Linode: 500 error" in captured_text
169169

0 commit comments

Comments
 (0)