Skip to content

Commit a178f93

Browse files
committed
test-bots: Detect absent __init__.py & optionally exit.
1 parent bda6783 commit a178f93

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tools/test-bots

+13-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ the tests for xkcd and wikipedia bots):
4646
nargs='*',
4747
default=[],
4848
help='bot(s) to exclude')
49+
parser.add_argument('--error-on-no-init',
50+
default=False,
51+
action="store_true",
52+
help="whether to exit if a bot has tests which won't run due to no __init__.py")
4953
return parser.parse_args()
5054

5155

@@ -76,15 +80,20 @@ def main():
7680

7781
bots_to_test = filter(lambda bot: bot not in options.exclude, specified_bots)
7882

79-
# Should add a check here that __init__.py is absent if test_*.py is present?
80-
8183
# Codecov seems to work only when using loader.discover. It failed to
8284
# capture line executions for functions like loader.loadTestFromModule
8385
# or loader.loadTestFromNames.
8486
top_level = "zulip_bots/zulip_bots/bots/"
8587
loader = unittest.defaultTestLoader
86-
test_suites = [loader.discover(top_level + name, top_level_dir=top_level)
87-
for name in bots_to_test]
88+
test_suites = []
89+
for name in bots_to_test:
90+
try:
91+
test_suites.append(loader.discover(top_level + name, top_level_dir=top_level))
92+
except ImportError as exception:
93+
print(exception)
94+
print("This likely indicates that you need a '__init__.py' file in your bot directory.")
95+
if options.error_on_no_init:
96+
sys.exit(1)
8897

8998
def filter_tests(tests):
9099
# type: (Union[TestSuite, TestCase]) -> TestSuite

0 commit comments

Comments
 (0)