mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-10-14 08:53:44 +02:00
Use hatch test/fmt subcommands, add parallel tests
This commit is contained in:
parent
32130774d7
commit
eb9847d0c4
@ -145,21 +145,15 @@ # DEVELOPER INSTRUCTIONS
|
||||
$ hatch run setup
|
||||
```
|
||||
|
||||
to install a `pre-commit` hook so that required checks (linting, formatting) will run automatically before each commit. If any of the checks fail, then the commit will be blocked; you'll need to fix the failing case and then you can commit the fixed version.
|
||||
to install a `pre-commit` hook so that required checks/fixes (linting, formatting) will run automatically before each commit. If any code needed to be linted or formatted, then the necessary changes will be made, but the commit will be blocked; you can review the edits and re-commit the fixed version.
|
||||
|
||||
After this you can use `hatch shell` to enable a virtual environment that has `yt-dlp` and its development dependencies installed.
|
||||
|
||||
In addition, the following script commands can be used to run simple tasks such as linting or testing (without having to run `hatch shell` first):
|
||||
* `hatch run format`: Format the code according to yt-dlp code standards
|
||||
* `hatch run lint`: Find common issues and automatically fix some of them
|
||||
* `hatch run fix`: Automatically fix linter violations and apply required code formatting changes
|
||||
* `hatch run check`: Check if the code is formatted and linted
|
||||
* `hatch run test`: Run extractor or core tests
|
||||
|
||||
You can run scripts for all available and supported python versions sequentially by setting the `TEST_ALL` variable:
|
||||
```shell
|
||||
$ TEST_ALL=1 hatch run test core
|
||||
```
|
||||
* `hatch fmt`: Automatically fix linter violations and apply required code formatting changes
|
||||
* See `hatch fmt --help` for more info
|
||||
* `hatch test`: Run extractor or core tests
|
||||
* See `hatch test --help` for more info
|
||||
|
||||
See item 6 of [new extractor tutorial](#adding-support-for-a-new-site) for how to run extractor specific test cases.
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
import functools
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@ -18,6 +19,8 @@ def parse_args():
|
||||
'test', help='a extractor tests, or one of "core" or "download"', nargs='*')
|
||||
parser.add_argument(
|
||||
'-k', help='run a test matching EXPRESSION. Same as "pytest -k"', metavar='EXPRESSION')
|
||||
parser.add_argument(
|
||||
'--pytest-args', help='arguments to passthrough to pytest')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -26,7 +29,8 @@ def run_tests(*tests, pattern=None, ci=False):
|
||||
run_download = 'download' in tests
|
||||
tests = list(map(fix_test_name, tests))
|
||||
|
||||
arguments = ['pytest', '-Werror', '--tb=short']
|
||||
pytest_args = args.pytest_args or os.getenv('HATCH_TEST_ARGS', '')
|
||||
arguments = ['pytest', '-Werror', '--tb=short', *shlex.split(pytest_args)]
|
||||
if ci:
|
||||
arguments.append('--color=yes')
|
||||
if pattern:
|
||||
|
@ -129,19 +129,35 @@ path = ".venv"
|
||||
|
||||
[tool.hatch.envs.default.scripts]
|
||||
setup = "pre-commit install"
|
||||
fix = [
|
||||
"format",
|
||||
"lint",
|
||||
]
|
||||
lint = "ruff check --fix {args:.}"
|
||||
format = "autopep8 --in-place {args:.}"
|
||||
check = [
|
||||
"ruff check {args:.}",
|
||||
"autopep8 --diff {args:.}",
|
||||
]
|
||||
test = "python -m devscripts.run_tests {args}"
|
||||
|
||||
[[tool.hatch.envs.default.overrides.env.TEST_ALL.matrix.value]]
|
||||
[tool.hatch.envs.hatch-static-analysis]
|
||||
detached = true
|
||||
dependencies = [
|
||||
"autopep8~=2.0",
|
||||
"ruff==0.4.*",
|
||||
]
|
||||
config-path = "pyproject.toml"
|
||||
|
||||
[tool.hatch.envs.hatch-static-analysis.scripts]
|
||||
format-check = "autopep8 --diff {args:.}"
|
||||
format-fix = "autopep8 --in-place {args:.}"
|
||||
lint-check = "ruff check {args:.}"
|
||||
lint-fix = "ruff check --fix {args:.}"
|
||||
|
||||
[tool.hatch.envs.hatch-test]
|
||||
features = ["default"]
|
||||
dependencies = [
|
||||
"pytest~=8.1",
|
||||
"pytest-randomly~=3.15",
|
||||
"pytest-rerunfailures~=14.0",
|
||||
"pytest-xdist[psutil]~=3.5",
|
||||
]
|
||||
|
||||
[tool.hatch.envs.hatch-test.scripts]
|
||||
run = "python -m devscripts.run_tests {args}"
|
||||
run-cov = "echo Code coverage not implemented && exit 1"
|
||||
|
||||
[[tool.hatch.envs.hatch-test.matrix]]
|
||||
python = [
|
||||
"3.8",
|
||||
"3.9",
|
||||
|
Loading…
Reference in New Issue
Block a user