]>
jfr.im git - yt-dlp.git/blob - devscripts/run_tests.py
b0c6ee67afd91b8b3d431de56e41ceba4047c877
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):
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
.extend(['-m', 'not download'])
33 arguments
.extend(['-m', 'download'])
35 arguments
.extend(['-k', pattern
])
38 f
'test/test_download.py::TestDownload::test_{test}' for test
in tests
)
40 print(f
'Running {arguments}')
42 subprocess
.run(arguments
)
44 except FileNotFoundError
:
47 arguments
= [sys
.executable
, '-Werror', '-m', 'unittest']
49 print('"pytest" needs to be installed to run core tests', file=sys
.stderr
)
52 arguments
.append('test.test_download')
54 arguments
.extend(['-k', pattern
])
57 f
'test.test_download.TestDownload.test_{test}' for test
in tests
)
59 print(f
'Running {arguments}')
60 subprocess
.run(arguments
)
63 if __name__
== '__main__':
67 os
.chdir(Path(__file__
).parent
.parent
)
68 run_tests(*args
.test
, pattern
=args
.k
)
69 except KeyboardInterrupt: