Skip to content

Commit 4908f40

Browse files
authored
Merge pull request #400 from wxtim/tests.fix_broken
Test: Fix broken test
2 parents a0d626b + 1b20098 commit 4908f40

File tree

5 files changed

+28
-42
lines changed

5 files changed

+28
-42
lines changed

tests/conftest.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,11 @@ async def _inner(srcpath, args=None, n_args=3):
192192
options = Options(parser, args)()
193193
output = SimpleNamespace()
194194

195-
try:
196-
if n_args == 3:
197-
await script(parser, options, str(srcpath))
198-
if n_args == 2:
199-
# Don't include the parser:
200-
await script(options, str(srcpath))
201-
output.ret = 0
202-
output.exc = ''
203-
except Exception as exc:
204-
output.ret = 1
205-
output.exc = exc
195+
if n_args == 3:
196+
await script(parser, options, str(srcpath))
197+
if n_args == 2:
198+
# Don't include the parser:
199+
await script(options, str(srcpath))
206200

207201
output.logging = '\n'.join([i.message for i in caplog.records])
208202
output.out, output.err = capsys.readouterr()
@@ -319,7 +313,7 @@ async def _inner(wid, args):
319313
for script_name, n_args in {
320314
'config': 3,
321315
'list': 2,
322-
'graph': 3,
316+
'graph': 2,
323317
'view': 2,
324318
'validate': 3,
325319
}.items():
@@ -351,9 +345,6 @@ async def _inner(wid, args):
351345
script_module.get_option_parser,
352346
)(wid, args, n_args=n_args)
353347

354-
# Check outputs
355-
assert all(output.ret == 0 for output in results.values())
356-
357348
# Return results for more checking if required:
358349
return results
359350

tests/functional/test_pre_configure.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,24 @@
1919
from itertools import product
2020
import os
2121
from pathlib import Path
22+
import re
2223
from shlex import split
2324
from subprocess import run
2425
from types import SimpleNamespace
2526

2627
import pytest
27-
from pytest import param
2828

29+
from cylc.flow.exceptions import InputError
2930
from cylc.rose.entry_points import pre_configure
3031
from cylc.rose.utilities import NotARoseSuiteException, load_rose_config
3132

3233

33-
@pytest.mark.parametrize(
34-
'srcdir, expect',
35-
[
36-
param(
37-
'07_cli_override',
38-
'failed 1.1\n(add --verbose for more context)',
39-
id='template variable not set'
40-
)
41-
]
42-
)
43-
async def test_validate_fail(srcdir, expect, cylc_validate_cli):
44-
srcdir = Path(__file__).parent / srcdir
45-
validate = await cylc_validate_cli(srcdir)
46-
assert validate.ret == 1
47-
if expect:
48-
assert expect == str(validate.exc)
34+
async def test_validate_fail_tvar_not_set(cylc_validate_cli):
35+
with pytest.raises(
36+
InputError,
37+
match=re.escape('failed 1.1\n(add --verbose for more context)')
38+
):
39+
await cylc_validate_cli(Path(__file__).parent / '07_cli_override')
4940

5041

5142
@pytest.mark.parametrize(
@@ -75,8 +66,8 @@ async def test_validate(monkeypatch, srcdir, envvars, args, cylc_validate_cli):
7566
for key, value in (envvars or {}).items():
7667
monkeypatch.setenv(key, value)
7768
srcdir = Path(__file__).parent / srcdir
78-
validate = await cylc_validate_cli(str(srcdir), args)
79-
assert validate.ret == 0
69+
# this is the test, we just asserting that this doesn't fail:
70+
await cylc_validate_cli(str(srcdir), args)
8071

8172

8273
@pytest.mark.parametrize(
@@ -241,11 +232,14 @@ async def test_validate_against_source(
241232
await cylc_inspect_scripts(wid, {"against_source": True})
242233

243234
# Reinstall fails if we clear rose install opts:
244-
clear_install_validate = await cylc_validate_cli(
245-
wid, {"against_source": True, 'clear_rose_install_opts': True}
246-
)
247-
assert clear_install_validate.ret != 0
248-
assert 'Test --rose-template-variable' in str(clear_install_validate.exc)
235+
with pytest.raises(InputError, match='Test --rose-template-variable'):
236+
await cylc_validate_cli(
237+
wid,
238+
{
239+
"against_source": True,
240+
'clear_rose_install_opts': True
241+
}
242+
)
249243

250244

251245
def test_invalid_cli_opts(tmp_path, caplog):

tests/functional/test_reinstall.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ async def fixture_install_flow(
108108
async def test_cylc_validate(fixture_provide_flow, cylc_validate_cli):
109109
"""Sanity check that workflow validates:
110110
"""
111-
srcpath = fixture_provide_flow['srcpath']
112-
assert (await cylc_validate_cli(str(srcpath))).ret == 0
111+
await cylc_validate_cli(str(fixture_provide_flow['srcpath']))
113112

114113

115114
@pytest.mark.parametrize(

tests/functional/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ async def test_global_config_environment_validate(
7373

7474
# Validate the config:
7575
output = await cylc_validate_cli(tmp_path)
76-
assert output.ret == 0
7776

7877
# CYLC_SYMLINKS == None the first time the global.cylc
7978
# is loaded and "Foo" the second time.

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ ignore=
88
W504
99
; "experimental" SIM9xx rules (flake8-simplify)
1010
SIM9
11+
; not all exception subclass __init__ args passed to super __init__
12+
; see https://github.com/cylc/cylc-flow/issues/7059
13+
B042
1114

1215
exclude=
1316
build,

0 commit comments

Comments
 (0)