test-bots: Add option to use pytest for running tests.
* Add pytest to requirements.txt * Add pass-through option to run pytest in verbose mode * Use various default pytest options * Exclude merels bot for now
This commit is contained in:
parent
69fab99ba7
commit
d73fa0f50f
|
@ -3,6 +3,7 @@ twine
|
||||||
coverage>=4.4.1
|
coverage>=4.4.1
|
||||||
pycodestyle==2.3.1
|
pycodestyle==2.3.1
|
||||||
mock
|
mock
|
||||||
|
pytest
|
||||||
-e ./zulip
|
-e ./zulip
|
||||||
-e ./zulip_bots
|
-e ./zulip_bots
|
||||||
-e ./zulip_botserver
|
-e ./zulip_botserver
|
||||||
|
|
|
@ -9,6 +9,7 @@ import argparse
|
||||||
import glob
|
import glob
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import TestCase, TestSuite
|
from unittest import TestCase, TestSuite
|
||||||
|
import pytest
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
description = """
|
description = """
|
||||||
|
@ -50,6 +51,14 @@ the tests for xkcd and wikipedia bots):
|
||||||
default=False,
|
default=False,
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="whether to exit if a bot has tests which won't run due to no __init__.py")
|
help="whether to exit if a bot has tests which won't run due to no __init__.py")
|
||||||
|
parser.add_argument('--pytest', '-p',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help="run tests with pytest")
|
||||||
|
parser.add_argument('--verbose', '-v',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='show verbose output (with pytest)')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +89,21 @@ 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)
|
||||||
|
|
||||||
|
if options.pytest:
|
||||||
|
excluded_bots = ['merels']
|
||||||
|
pytest_bots_to_test = sorted([bot for bot in bots_to_test if bot not in excluded_bots])
|
||||||
|
pytest_options = [
|
||||||
|
'-s', # show output from tests; this hides the progress bar though
|
||||||
|
'-x', # stop on first test failure
|
||||||
|
'--ff', # runs last failure first
|
||||||
|
]
|
||||||
|
pytest_options += (['-v'] if options.verbose else [])
|
||||||
|
os.chdir(bots_dir)
|
||||||
|
result = pytest.main(pytest_bots_to_test + pytest_options)
|
||||||
|
if result != 0:
|
||||||
|
sys.exit(1)
|
||||||
|
failures = False
|
||||||
|
else:
|
||||||
# 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.
|
||||||
|
@ -98,10 +122,11 @@ def main():
|
||||||
suite = unittest.TestSuite(test_suites)
|
suite = unittest.TestSuite(test_suites)
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
result = runner.run(suite)
|
result = runner.run(suite)
|
||||||
if result.failures or result.errors:
|
failures = result.failures
|
||||||
|
if failures or result.errors:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not result.failures and options.coverage:
|
if not failures and options.coverage:
|
||||||
cov.stop()
|
cov.stop()
|
||||||
cov.data_suffix = False # Disable suffix so that filename is .coverage
|
cov.data_suffix = False # Disable suffix so that filename is .coverage
|
||||||
cov.save()
|
cov.save()
|
||||||
|
|
Loading…
Reference in a new issue