10 from pathlib
import Path
13 fix_test_name
= functools
.partial(re
.compile(r
'IE(_all|_\d+)?$').sub
, r
'\1')
17 parser
= argparse
.ArgumentParser(description
='Run selected yt-dlp tests')
19 'test', help='an extractor test, test path, or one of "core" or "download"', nargs
='*')
21 '-k', help='run a test matching EXPRESSION. Same as "pytest -k"', metavar
='EXPRESSION')
23 '--pytest-args', help='arguments to passthrough to pytest')
24 return parser
.parse_args()
27 def run_tests(*tests
, pattern
=None, ci
=False):
28 run_core
= 'core' in tests
or (not pattern
and not tests
)
29 run_download
= 'download' in tests
31 pytest_args
= args
.pytest_args
or os
.getenv('HATCH_TEST_ARGS', '')
32 arguments
= ['pytest', '-Werror', '--tb=short', *shlex
.split(pytest_args
)]
34 arguments
.append('--color=yes')
36 arguments
.extend(['-k', pattern
])
38 arguments
.extend(['-m', 'not download'])
40 arguments
.extend(['-m', 'download'])
44 else f
'test/test_download.py::TestDownload::test_{fix_test_name(test)}'
47 print(f
'Running {arguments}', flush
=True)
49 return subprocess
.call(arguments
)
50 except FileNotFoundError
:
53 arguments
= [sys
.executable
, '-Werror', '-m', 'unittest']
55 arguments
.extend(['-k', pattern
])
57 print('"pytest" needs to be installed to run core tests', file=sys
.stderr
, flush
=True)
60 arguments
.append('test.test_download')
63 f
'test.test_download.TestDownload.test_{test}' for test
in tests
)
65 print(f
'Running {arguments}', flush
=True)
66 return subprocess
.call(arguments
)
69 if __name__
== '__main__':
73 os
.chdir(Path(__file__
).parent
.parent
)
74 sys
.exit(run_tests(*args
.test
, pattern
=args
.k
, ci
=bool(os
.getenv('CI'))))
75 except KeyboardInterrupt: