|
13 | 13 | import samples.tools |
14 | 14 |
|
15 | 15 | def run_all_samples(): |
16 | | - for _, sample_name, _ in pkgutil.walk_packages(samples.__path__): |
17 | | - sample_module = importlib.import_module('samples.'+sample_name) |
18 | | - subkey_env_name = getattr(sample_module, "SUBSCRIPTION_KEY_ENV_NAME", None) |
19 | | - if not subkey_env_name: |
| 16 | + for _, section_name_name, ispkg in pkgutil.walk_packages(samples.__path__): |
| 17 | + if not ispkg: |
20 | 18 | continue |
21 | | - print("Executing sample from ", sample_name) |
22 | | - sample_module = importlib.import_module('samples.'+sample_name) |
23 | | - samples.tools.execute_samples(sample_module.__dict__, subkey_env_name) |
| 19 | + section_package_name = "samples."+section_name_name |
| 20 | + section_package = importlib.import_module(section_package_name) |
| 21 | + for _, sample_name, _ in pkgutil.iter_modules(section_package.__path__): |
| 22 | + sample_module = importlib.import_module(section_package_name+"."+sample_name) |
| 23 | + subkey_env_name = getattr(sample_module, "SUBSCRIPTION_KEY_ENV_NAME", None) |
| 24 | + if not subkey_env_name: |
| 25 | + continue |
| 26 | + print("Executing sample from ", sample_name) |
| 27 | + try: |
| 28 | + samples.tools.execute_samples(sample_module.__dict__, subkey_env_name) |
| 29 | + except samples.tools.SubscriptionKeyError as err: |
| 30 | + print("{}\n".format(err)) |
24 | 31 |
|
25 | 32 | if __name__ == "__main__": |
26 | 33 | run_all_samples() |
0 commit comments