Skip to content

Commit 15eafe7

Browse files
committed
slight refactor, better failure output
1 parent aa63390 commit 15eafe7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: end_to_end_tests/functional_tests/helpers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def _decorator(cls):
4747
nonlocal alias
4848

4949
def _func(self, generated_client):
50-
module = generated_client.import_module(module_name)
51-
return getattr(module, import_name)
50+
return generated_client.import_symbol(module_name, import_name)
5251

5352
alias = alias or import_name
5453
_func.__name__ = alias

Diff for: end_to_end_tests/generated_client.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def import_module(self, module_path: str) -> Any:
4545
"""Attempt to import a module from the generated code."""
4646
return importlib.import_module(f"{self.base_module}{module_path}")
4747

48+
def import_symbol(self, module_path: str, name: str) -> Any:
49+
module = self.import_module(module_path)
50+
try:
51+
return getattr(module, name)
52+
except AttributeError:
53+
existing = ", ".join(name for name in dir(module) if not name.startswith("_"))
54+
assert False, (
55+
f"Couldn't find import \"{name}\" in \"{self.base_module}{module_path}\".\n"
56+
f"Available imports in that module are: {existing}\n"
57+
f"Output from generator was: {self.generator_result.stdout}"
58+
)
4859

4960
def _run_command(
5061
command: str,
@@ -67,7 +78,8 @@ def _run_command(
6778
args.extend(extra_args)
6879
result = runner.invoke(app, args)
6980
if result.exit_code != 0 and raise_on_error:
70-
raise Exception(result.stdout)
81+
message = f"{result.stdout}\n{result.exception}" if result.exception else result.stdout
82+
raise Exception(message)
7183
return result
7284

7385

0 commit comments

Comments
 (0)