test-bots: Detect absent __init__.py & optionally exit.
This commit is contained in:
parent
bda678344f
commit
a178f93087
|
@ -46,6 +46,10 @@ the tests for xkcd and wikipedia bots):
|
||||||
nargs='*',
|
nargs='*',
|
||||||
default=[],
|
default=[],
|
||||||
help='bot(s) to exclude')
|
help='bot(s) to exclude')
|
||||||
|
parser.add_argument('--error-on-no-init',
|
||||||
|
default=False,
|
||||||
|
action="store_true",
|
||||||
|
help="whether to exit if a bot has tests which won't run due to no __init__.py")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,15 +80,20 @@ def main():
|
||||||
|
|
||||||
bots_to_test = filter(lambda bot: bot not in options.exclude, specified_bots)
|
bots_to_test = filter(lambda bot: bot not in options.exclude, specified_bots)
|
||||||
|
|
||||||
# Should add a check here that __init__.py is absent if test_*.py is present?
|
|
||||||
|
|
||||||
# Codecov seems to work only when using loader.discover. It failed to
|
# Codecov seems to work only when using loader.discover. It failed to
|
||||||
# capture line executions for functions like loader.loadTestFromModule
|
# capture line executions for functions like loader.loadTestFromModule
|
||||||
# or loader.loadTestFromNames.
|
# or loader.loadTestFromNames.
|
||||||
top_level = "zulip_bots/zulip_bots/bots/"
|
top_level = "zulip_bots/zulip_bots/bots/"
|
||||||
loader = unittest.defaultTestLoader
|
loader = unittest.defaultTestLoader
|
||||||
test_suites = [loader.discover(top_level + name, top_level_dir=top_level)
|
test_suites = []
|
||||||
for name in bots_to_test]
|
for name in bots_to_test:
|
||||||
|
try:
|
||||||
|
test_suites.append(loader.discover(top_level + name, top_level_dir=top_level))
|
||||||
|
except ImportError as exception:
|
||||||
|
print(exception)
|
||||||
|
print("This likely indicates that you need a '__init__.py' file in your bot directory.")
|
||||||
|
if options.error_on_no_init:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def filter_tests(tests):
|
def filter_tests(tests):
|
||||||
# type: (Union[TestSuite, TestCase]) -> TestSuite
|
# type: (Union[TestSuite, TestCase]) -> TestSuite
|
||||||
|
|
Loading…
Reference in a new issue