Skip to content

Commit

Permalink
Add integration test for basedir module loading failures
Browse files Browse the repository at this point in the history
  • Loading branch information
timofurrer committed Feb 16, 2020
1 parent d179bb8 commit c23d93b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/radish/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,17 @@ def cli(**kwargs):
sys.exit(1)

logger.debug("Loading all modules from the basedirs")
loaded_modules = loader.load_modules(config.basedirs)
try:
loaded_modules = loader.load_modules(config.basedirs)
except Exception as exc:
print("", flush=True)
print("An error occured while loading modules from the basedirs:", flush=True)
print(exc, flush=True)
if config.with_traceback:
print("", flush=True)
traceback.print_exc()
sys.exit(1)

logger.debug(
"Loaded %d modules from the basedirs: %s",
len(loaded_modules),
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/features/Error-Reporting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,29 @@ Feature: Hook Error Reporting
An error occured while running the Feature Files:
The '@before.each_feature' Hook 'before_each_feature' raised an RuntimeError: some runtime Error occurred
"""

Scenario: Error Reporting on Exceptions raised during Module import
Given the Feature File "error-reporting.feature"
"""
Feature: Some Feature
Scenario: Some Scenario
Given some Step
"""
And the base dir module "steps.py"
"""
from radish import given, before
def some_func():
raise RuntimeError("some runtime Error occurred")
some_func()
"""
When the "error-reporting.feature" is run
Then the exit code should be 1
And the output to match:
"""
An error occured while loading modules from the basedirs:
Unable to import module 'steps' from '(.*?)/steps.py': some runtime Error occurred
"""

0 comments on commit c23d93b

Please sign in to comment.