Skip to content

Commit

Permalink
feat: add --quiet option to test/run.py and refactor the runner
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Nov 7, 2024
1 parent 65149e5 commit 472672d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
other: run the other tests
"""

import argparse
import os
import re
import sys
Expand Down Expand Up @@ -97,7 +98,7 @@ def describe_suite(suite: TestSuite):
SUITES = ["all", "dev", "e2e", "prod", "api", "other"]


def run_tests(suite: str, describe: bool = False) -> bool:
def run_tests(suite: str, describe: bool = False, verbosity=3) -> bool:
"""Run the specified test suite.
Args:
Expand Down Expand Up @@ -131,18 +132,27 @@ def run_tests(suite: str, describe: bool = False) -> bool:
describe_suite(test_suite)
return True
else:
runner = TextTestRunner(verbosity=3)
runner = TextTestRunner(verbosity=verbosity)
success = runner.run(test_suite).wasSuccessful()
if not success:
LOGGER.error("Some tests failed. Please see log above.")
return success


if __name__ == "__main__":
describe = "--describe" in sys.argv
if describe:
sys.argv.remove("--describe")

result = run_tests("" if len(sys.argv) <= 1 else sys.argv[1], describe)
parser = argparse.ArgumentParser(description="Run ReadAlongs/Studio test suites.")
parser.add_argument("--quiet", "-q", action="store_true", help="reduce output")
parser.add_argument(
"--describe", action="store_true", help="describe the selected test suite"
)
parser.add_argument(
"suite",
nargs="?",
default="dev",
help="the test suite to run [dev]",
choices=SUITES,
)
args = parser.parse_args()
result = run_tests(args.suite, args.describe, 1 if args.quiet else 3)
if not result:
sys.exit(1)

0 comments on commit 472672d

Please sign in to comment.