Skip to content

Commit c389b2f

Browse files
committed
Avoid using only_if_module_is_available as it will raise an error
1 parent 6c91f81 commit c389b2f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

test/framework/build_log.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from easybuild.tools.build_log import (
4141
LOGGING_FORMAT, EasyBuildError, EasyBuildLog, dry_run_msg, dry_run_warning, init_logging, print_error,
4242
print_error_and_exit, print_msg, print_warning, stop_logging, time_str_since, raise_nosupport)
43-
from easybuild.tools.utilities import only_if_module_is_available
4443
from easybuild.tools.config import update_build_option
4544
from easybuild.tools.filetools import read_file, write_file
4645

@@ -338,9 +337,12 @@ def run_check(msg, args, expected_stdout='', expected_stderr='', **kwargs):
338337

339338
self.assertErrorRegex(EasyBuildError, "Unknown named arguments", print_msg, 'foo', unknown_arg='bar')
340339

341-
@only_if_module_is_available('rich')
342340
def test_print_msg_rich(self):
343341
"""Test print_msg"""
342+
try:
343+
import rich
344+
except ImportError:
345+
self.skipTest("rich not available")
344346
update_build_option('output_style', 'rich')
345347

346348
def run_check(msg, args, expected_stdout='', expected_stderr='', **kwargs):

test/framework/output.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from easybuild.tools.output import PROGRESS_BAR_EXTENSIONS, PROGRESS_BAR_TYPES
3838
from easybuild.tools.output import DummyRich, colorize, get_progress_bar, print_error, show_progress_bars
3939
from easybuild.tools.output import start_progress_bar, status_bar, stop_progress_bar, update_progress_bar, use_rich
40-
from easybuild.tools.utilities import only_if_module_is_available
4140

4241
try:
4342
import rich.progress
@@ -142,11 +141,15 @@ def test_colorize(self):
142141

143142
self.assertErrorRegex(EasyBuildError, "Unknown color: nosuchcolor", colorize, 'test', 'nosuchcolor')
144143

145-
@only_if_module_is_available('rich')
146144
def test_colorize_rich(self):
147145
"""
148146
Test colorize function
149147
"""
148+
try:
149+
import rich
150+
print(rich)
151+
except ImportError:
152+
self.skipTest("rich not available")
150153
update_build_option('output_style', 'rich')
151154
for color in ('blue', 'cyan', 'green', 'purple', 'red', 'yellow'):
152155
self.assertEqual(colorize('test', color), '[bold %s]test[/bold %s]' % (color, color))
@@ -170,11 +173,14 @@ def test_print_error(self):
170173
expected = '\n\nThis is yellow: \x1b[1;33ma banana\x1b[0m\n\n'
171174
self.assertEqual(stderr, expected)
172175

173-
@only_if_module_is_available('rich')
174176
def test_print_error_rich(self):
175177
"""
176178
Test print_error function
177179
"""
180+
try:
181+
import rich
182+
except ImportError:
183+
self.skipTest("rich not available")
178184
update_build_option('output_style', 'rich')
179185
msg = "This is yellow: " + colorize("a banana", color='yellow')
180186
self.mock_stderr(True)

0 commit comments

Comments
 (0)