Authored by: Grub4K
This commit is contained in:
Simon Sawicki 2023-12-26 19:55:30 +01:00
parent 2d1d683a54
commit 225cf2b830
No known key found for this signature in database

View file

@ -21,12 +21,14 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
def run_tests(*tests, pattern=None): def run_tests(*tests, pattern=None, ci=False):
run_core = 'core' in tests or (not pattern and not tests) run_core = 'core' in tests or (not pattern and not tests)
run_download = 'download' in tests run_download = 'download' in tests
tests = list(map(fix_test_name, tests)) tests = list(map(fix_test_name, tests))
arguments = ['pytest', '-Werror', '--tb', 'short'] arguments = ['pytest', '-Werror', '--tb=short']
if ci:
arguments.append('--color=yes')
if run_core: if run_core:
arguments.extend(['-m', 'not download']) arguments.extend(['-m', 'not download'])
elif run_download: elif run_download:
@ -37,17 +39,16 @@ def run_tests(*tests, pattern=None):
arguments.extend( arguments.extend(
f'test/test_download.py::TestDownload::test_{test}' for test in tests) f'test/test_download.py::TestDownload::test_{test}' for test in tests)
print(f'Running {arguments}') print(f'Running {arguments}', flush=True)
try: try:
subprocess.run(arguments) return subprocess.call(arguments)
return
except FileNotFoundError: except FileNotFoundError:
pass pass
arguments = [sys.executable, '-Werror', '-m', 'unittest'] arguments = [sys.executable, '-Werror', '-m', 'unittest']
if run_core: if run_core:
print('"pytest" needs to be installed to run core tests', file=sys.stderr) print('"pytest" needs to be installed to run core tests', file=sys.stderr, flush=True)
return return 1
elif run_download: elif run_download:
arguments.append('test.test_download') arguments.append('test.test_download')
elif pattern: elif pattern:
@ -56,8 +57,8 @@ def run_tests(*tests, pattern=None):
arguments.extend( arguments.extend(
f'test.test_download.TestDownload.test_{test}' for test in tests) f'test.test_download.TestDownload.test_{test}' for test in tests)
print(f'Running {arguments}') print(f'Running {arguments}', flush=True)
subprocess.run(arguments) return subprocess.call(arguments)
if __name__ == '__main__': if __name__ == '__main__':
@ -65,6 +66,6 @@ if __name__ == '__main__':
args = parse_args() args = parse_args()
os.chdir(Path(__file__).parent.parent) os.chdir(Path(__file__).parent.parent)
run_tests(*args.test, pattern=args.k) sys.exit(run_tests(*args.test, pattern=args.k, ci=bool(os.getenv('CI'))))
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass