summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2022-05-03 18:39:00 +0200
committerGitHub <noreply@github.com>2022-05-03 09:39:00 -0700
commita5e92893d3b127a3d71f2566f57d8f4499e38719 (patch)
tree9dcf8e24041dcc2d13543f9172b09c5fec1912dd /lib
parentbdef031d4e7208c0812d0fdc30f006f87b1ad476 (diff)
downloadspack-a5e92893d3b127a3d71f2566f57d8f4499e38719.tar.gz
spack-a5e92893d3b127a3d71f2566f57d8f4499e38719.tar.bz2
spack-a5e92893d3b127a3d71f2566f57d8f4499e38719.tar.xz
spack-a5e92893d3b127a3d71f2566f57d8f4499e38719.zip
Simplify fixture used to test `spack info` (#30456)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/info.py28
1 files changed, 10 insertions, 18 deletions
diff --git a/lib/spack/spack/test/cmd/info.py b/lib/spack/spack/test/cmd/info.py
index a5e8ae0bd8..57176a4784 100644
--- a/lib/spack/spack/test/cmd/info.py
+++ b/lib/spack/spack/test/cmd/info.py
@@ -26,18 +26,14 @@ def parser():
@pytest.fixture()
-def info_lines():
- lines = []
- return lines
-
-
-@pytest.fixture()
-def mock_print(monkeypatch, info_lines):
+def print_buffer(monkeypatch):
+ buffer = []
def _print(*args):
- info_lines.extend(args)
+ buffer.extend(args)
monkeypatch.setattr(spack.cmd.info.color, 'cprint', _print, raising=False)
+ return buffer
@pytest.mark.parametrize('pkg', [
@@ -52,11 +48,11 @@ def test_it_just_runs(pkg):
info(pkg)
-def test_info_noversion(mock_packages, info_lines, mock_print):
+def test_info_noversion(mock_packages, print_buffer):
"""Check that a mock package with no versions or variants outputs None."""
info('noversion')
- line_iter = info_lines.__iter__()
+ line_iter = iter(print_buffer)
for line in line_iter:
if 'version' in line:
has = [desc in line for desc in ['Preferred', 'Safe', 'Deprecated']]
@@ -72,12 +68,11 @@ def test_info_noversion(mock_packages, info_lines, mock_print):
('zlib', 'False'),
('gcc', 'True (version, variants)'),
])
-@pytest.mark.usefixtures('mock_print')
-def test_is_externally_detectable(pkg_query, expected, parser, info_lines):
+def test_is_externally_detectable(pkg_query, expected, parser, print_buffer):
args = parser.parse_args(['--detectable', pkg_query])
spack.cmd.info.info(parser, args)
- line_iter = info_lines.__iter__()
+ line_iter = iter(print_buffer)
for line in line_iter:
if 'Externally Detectable' in line:
is_externally_detectable = next(line_iter).strip()
@@ -90,9 +85,7 @@ def test_is_externally_detectable(pkg_query, expected, parser, info_lines):
'trilinos',
'gcc' # This should ensure --test's c_names processing loop covered
])
-@pytest.mark.usefixtures('mock_print')
-def test_info_fields(pkg_query, parser, info_lines):
-
+def test_info_fields(pkg_query, parser, print_buffer):
expected_fields = (
'Description:',
'Homepage:',
@@ -108,5 +101,4 @@ def test_info_fields(pkg_query, parser, info_lines):
spack.cmd.info.info(parser, args)
for text in expected_fields:
- match = [x for x in info_lines if text in x]
- assert match
+ assert any(x for x in print_buffer if text in x)