Skip to content

Commit 8db6c86

Browse files
authored
Improve pytest execution (#4435)
1 parent 900b979 commit 8db6c86

File tree

7 files changed

+39
-20
lines changed

7 files changed

+39
-20
lines changed

.config/constraints.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ pathspec==0.12.1 # via black, mkdocs, mkdocs-macros-plugin, yamllint, a
7474
pillow==11.0.0 # via cairosvg, mkdocs-ansible
7575
platformdirs==4.3.6 # via black, mkdocs-get-deps, mkdocstrings, pylint, tox, virtualenv
7676
pluggy==1.5.0 # via pytest, tox
77-
psutil==6.1.0 # via ansible-lint (pyproject.toml)
77+
psutil==6.1.0 # via pytest-xdist, ansible-lint (pyproject.toml)
7878
pycparser==2.22 # via cffi
7979
pygments==2.18.0 # via mkdocs-material, rich
80-
pylint==3.3.1 # via ansible-lint (pyproject.toml)
80+
pylint==3.3.2 # via ansible-lint (pyproject.toml)
8181
pymdown-extensions==10.12 # via markdown-exec, mkdocs-ansible, mkdocs-material, mkdocstrings
8282
pyproject-api==1.8.0 # via tox
83-
pytest==8.3.3 # via pytest-mock, pytest-plus, pytest-xdist, ansible-lint (pyproject.toml)
83+
pytest==8.3.4 # via pytest-instafail, pytest-mock, pytest-plus, pytest-xdist, ansible-lint (pyproject.toml)
84+
pytest-instafail==0.5.0 # via ansible-lint (pyproject.toml)
8485
pytest-mock==3.14.0 # via ansible-lint (pyproject.toml)
8586
pytest-plus==0.7.0 # via ansible-lint (pyproject.toml)
8687
pytest-xdist==3.6.1 # via ansible-lint (pyproject.toml)
@@ -95,6 +96,7 @@ rich==13.9.4 # via ansible-lint (pyproject.toml)
9596
rpds-py==0.22.1 # via jsonschema, referencing
9697
ruamel-yaml==0.18.6 # via ansible-lint (pyproject.toml)
9798
ruamel-yaml-clib==0.2.12 # via ruamel-yaml, ansible-lint (pyproject.toml)
99+
setproctitle==1.3.4 # via pytest-xdist
98100
six==1.16.0 # via python-dateutil
99101
soupsieve==2.6 # via beautifulsoup4
100102
subprocess-tee==0.4.2 # via ansible-compat, ansible-lint (pyproject.toml)

.config/requirements-test.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pylint # IDE support
1111
pytest >= 7.2.2
1212
pytest-mock
1313
pytest-plus >= 0.6 # for PYTEST_REQPASS
14-
pytest-xdist >= 2.1.0
14+
pytest-xdist[psutil,setproctitle] >= 2.1.0
15+
pytest-instafail >= 0.5.0 # only for local development, via PYTEST_ADDOPTS=-edit
1516
ruamel.yaml>=0.17.31
1617
ruamel-yaml-clib # needed for mypy
1718
tox >= 4.0.0

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ repos:
205205
- wcmatch
206206
- yamllint
207207
- repo: https://github.com/pycqa/pylint
208-
rev: v3.3.1
208+
rev: v3.3.2
209209
hooks:
210210
- id: pylint
211211
args:

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"**/*.txt",
1818
"**/*.md"
1919
],
20+
"python.experiments.optInto": [
21+
"pythonTestAdapter"
22+
],
2023
"python.terminal.activateEnvironment": true,
2124
"python.testing.pytestEnabled": true,
2225
"python.testing.unittestEnabled": false,

pyproject.toml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ reportPossiblyUnboundVariable = false
179179
[tool.pytest.ini_options]
180180
# do not add options here as this will likely break either console runs or IDE
181181
# integration like vscode or pycharm
182-
addopts = "-p no:pytest_cov --failed-first"
183-
# https://code.visualstudio.com/docs/python/testing
184-
# coverage is re-enabled in `tox.ini`. That approach is safer than
185-
# `--no-cov` which prevents activation from tox.ini and which also fails
186-
# when plugin is effectively missing.
182+
addopts = "-p no:pytest_cov --durations=10 --failed-first"
187183
doctest_optionflags = ["ALLOW_UNICODE", "ELLIPSIS"]
188184
filterwarnings = [
189185
"error",
@@ -200,11 +196,15 @@ filterwarnings = [
200196
"ignore:Attribute s is deprecated and will be removed in Python 3.14; use value instead:DeprecationWarning"
201197
]
202198
junit_duration_report = "call"
199+
junit_family = "xunit1"
203200
# Our github annotation parser from .github/workflows/tox.yml requires xunit1 format. Ref:
204201
# https://github.com/shyim/junit-report-annotations-action/issues/3#issuecomment-663241378
205-
junit_family = "xunit1"
206202
junit_suite_name = "ansible_lint_test_suite"
207203
minversion = "4.6.6"
204+
# https://code.visualstudio.com/docs/python/testing
205+
# coverage is re-enabled in `tox.ini`. That approach is safer than
206+
# `--no-cov` which prevents activation from tox.ini and which also fails
207+
# when plugin is effectively missing.
208208
norecursedirs = [
209209
"*.egg",
210210
".cache",
@@ -214,12 +214,19 @@ norecursedirs = [
214214
".github",
215215
".mypy_cache",
216216
".projects",
217+
".eggs",
217218
".tox",
219+
"__pycache__",
220+
"ansible_collections",
218221
"build",
219222
"collections",
220223
"dist",
221224
"docs",
222-
"src/ansible_lint.egg-info"
225+
"examples",
226+
"plugins",
227+
"site",
228+
"src/ansible_lint.egg-info",
229+
"test/schemas"
223230
]
224231
python_files = [
225232
"test_*.py",
@@ -333,6 +340,10 @@ in_place = true
333340
sort_inline_tables = true
334341
sort_table_keys = true
335342

343+
[tool.uv]
344+
# incompatible with Windows
345+
environments = ["platform_system != 'Windows'"]
346+
336347
[tool.uv.pip]
337348
annotation-style = "line"
338349
custom-compile-command = "tox run deps"

test/test_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ def test_cli_auto_detect(capfd: CaptureFixture[str]) -> None:
312312
"-v",
313313
"-p",
314314
"--nocolor",
315+
"--offline",
316+
"--exclude=examples",
317+
"--exclude=test",
318+
"--exclude=src",
319+
"--exclude=collections",
320+
"--exclude=.github",
315321
]
316322
result = subprocess.run(cmd, check=False).returncode
317323

@@ -321,18 +327,12 @@ def test_cli_auto_detect(capfd: CaptureFixture[str]) -> None:
321327
out, err = capfd.readouterr()
322328

323329
# An expected rule match from our examples
324-
assert (
325-
"examples/playbooks/empty_playbook.yml:1:1: "
326-
"syntax-check[empty-playbook]: Empty playbook, nothing to do" in out
327-
)
330+
assert "playbook.yml:6: name[casing]" in out
328331
# assures that our ansible-lint config exclude was effective in excluding github files
329332
assert "Identified: .github/" not in out
330333
# assures that we can parse playbooks as playbooks
331334
assert "Identified: test/test/always-run-success.yml" not in err
332-
assert (
333-
"Executing syntax check on playbook examples/playbooks/mocked_dependency.yml"
334-
in err
335-
)
335+
assert "Executing syntax check on playbook playbook.yml" in err
336336

337337

338338
def test_is_playbook() -> None:

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ setenv =
157157
# https://github.com/pawamoy/markdown-exec/issues/11
158158
NO_COLOR = 1
159159
TERM = dump
160+
# https://squidfunk.github.io/mkdocs-material/plugins/requirements/image-processing/#troubleshooting
161+
DYLD_FALLBACK_LIBRARY_PATH = /opt/homebrew/lib:{env:LD_LIBRARY_PATH}
160162
skip_install = false
161163
usedevelop = true
162164
commands_pre =

0 commit comments

Comments
 (0)