]>
jfr.im git - yt-dlp.git/blob - devscripts/run_tests.py
9 from pathlib
import Path
12 fix_test_name
= functools
.partial(re
.compile(r
'IE(_all|_\d+)?$').sub
, r
'\1')
16 parser
= argparse
.ArgumentParser(description
='Run selected yt-dlp tests')
18 'test', help='a extractor tests, or one of "core" or "download"', nargs
='*')
20 '-k', help='run a test matching EXPRESSION. Same as "pytest -k"', metavar
='EXPRESSION')
21 return parser
.parse_args()
24 def run_tests(*tests
, pattern
=None, ci
=False):
25 run_core
= 'core' in tests
or (not pattern
and not tests
)
26 run_download
= 'download' in tests
27 tests
= list(map(fix_test_name
, tests
))
29 arguments
= ['pytest', '-Werror', '--tb=short']
31 arguments
.append('--color=yes')
33 arguments
.extend(['-m', 'not download'])
35 arguments
.extend(['-m', 'download'])
37 arguments
.extend(['-k', pattern
])
40 f
'test/test_download.py::TestDownload::test_{test}' for test
in tests
)
42 print(f
'Running {arguments}', flush
=True)
44 return subprocess
.call(arguments
)
45 except FileNotFoundError
:
48 arguments
= [sys
.executable
, '-Werror', '-m', 'unittest']
50 print('"pytest" needs to be installed to run core tests', file=sys
.stderr
, flush
=True)
53 arguments
.append('test.test_download')
55 arguments
.extend(['-k', pattern
])
58 f
'test.test_download.TestDownload.test_{test}' for test
in tests
)
60 print(f
'Running {arguments}', flush
=True)
61 return subprocess
.call(arguments
)
64 if __name__
== '__main__':
68 os
.chdir(Path(__file__
).parent
.parent
)
69 sys
.exit(run_tests(*args
.test
, pattern
=args
.k
, ci
=bool(os
.getenv('CI'))))
70 except KeyboardInterrupt: