Skip to content

Commit 9a77349

Browse files
Update coverage and developer configuration (#157)
* Update developer configuration * chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix commands * Fix tox * chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Final fix for coverage error --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bf1744c commit 9a77349

File tree

8 files changed

+79
-39
lines changed

8 files changed

+79
-39
lines changed

.config/requirements-dev.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

.config/requirements-test.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
pytest
1+
black
22
coverage[toml]
3+
mypy
4+
pip-tools
5+
pre-commit
6+
pydoclint
7+
pytest
38
pytest-xdist
9+
ruff
10+
toml-sort
411
tox
12+
types-PyYAML

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@ cython_debug/
168168
# Version created and populated by setuptools_scm
169169
/src/*/_version.py
170170

171+
# Coverage files
172+
*.lcov
173+
171174
.DS_Store

.vscode/extensions.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"recommendations": [
3+
"charliermarsh.ruff",
4+
"esbenp.prettier-vscode",
5+
"markis.code-coverage",
36
"ms-python.black-formatter",
7+
"ms-python.debugpy",
8+
"ms-python.mypy-type-checker",
49
"ms-python.pylint",
5-
"charliermarsh.ruff",
6-
"matangover.mypy",
7-
"esbenp.prettier-vscode"
10+
"ms-python.python",
11+
"streetsidesoftware.code-spell-checker"
812
]
913
}

.vscode/settings.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"python.testing.unittestEnabled": false,
3-
"python.testing.pytestEnabled": true,
4-
// Override the pyproject.toml and disable xdist to enable test debugging
5-
"python.testing.pytestArgs": ["-n0", "--dist", "no"],
2+
"[jsonc]": {
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
},
65
"[python]": {
7-
"editor.formatOnSave": true,
86
"editor.codeActionsOnSave": {
9-
"source.fixAll": "explicit"
7+
"source.fixAll": "explicit",
8+
"source.organizeImports": "explicit"
109
},
11-
"editor.defaultFormatter": "charliermarsh.ruff"
10+
"editor.defaultFormatter": "ms-python.black-formatter",
11+
"editor.formatOnSave": true
1212
},
13-
"mypy.runUsingActiveInterpreter": true,
14-
"mypy.targets": ["src", "tests"],
15-
"[jsonc]": {
16-
"editor.defaultFormatter": "esbenp.prettier-vscode"
17-
}
13+
"markiscodecoverage.searchCriteria": "coverage.lcov",
14+
"mypy-type-checker.importStrategy": "fromEnvironment",
15+
"mypy-type-checker.preferDaemon": true,
16+
"mypy-type-checker.reportingScope": "workspace",
17+
"python.testing.pytestArgs": ["tests"],
18+
"python.testing.pytestEnabled": true,
19+
"python.testing.unittestEnabled": false
1820
}

pyproject.toml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ skip_covered = true
5252
skip_empty = true
5353

5454
[tool.coverage.run]
55-
concurrency = ["multiprocessing", "thread"]
55+
source_pkgs = ["ansible_dev_environment"]
5656
# Do not use branch until bug is fixes:
5757
# https://github.com/nedbat/coveragepy/issues/605
5858
# branch = true
5959
parallel = true
60-
source = ["src"]
60+
concurrency = ["multiprocessing", "thread"]
6161

6262
[tool.mypy]
6363
files = ["src", "tests"]
@@ -308,33 +308,42 @@ disable = [
308308
"unsubscriptable-object"
309309
]
310310

311+
[tool.pytest.ini_options]
312+
addopts = "-ra --showlocals --durations=10"
313+
testpaths = "tests"
314+
tmp_path_retention_policy = "failed"
315+
verbosity_assertions = 2
316+
311317
[tool.ruff]
312318
builtins = ["__"]
313319
fix = true
314320
line-length = 100
315-
select = ["ALL"]
316321
target-version = "py310"
317322

318-
[tool.ruff.flake8-pytest-style]
323+
[tool.ruff.lint]
324+
select = ["ALL"]
325+
326+
[tool.ruff.lint.flake8-pytest-style]
319327
parametrize-values-type = "tuple"
320328

321-
[tool.ruff.isort]
329+
[tool.ruff.lint.isort]
322330
lines-after-imports = 2 # Ensures consistency for cases when there's variable vs function/class definitions after imports
323331
lines-between-types = 1 # Separate import/from with 1 line
324332

325-
[tool.ruff.per-file-ignores]
333+
[tool.ruff.lint.per-file-ignores]
326334
# SLF001: Allow private member access in tests
327335
# S101 Allow assert in tests
328336
# S602 Allow shell in test
329337
# T201 Allow print in tests
330338
"tests/**" = ["SLF001", "S101", "S602", "T201"]
339+
# SIM108, file is generated
340+
"_version.py" = ["SIM108"]
331341

332-
[tool.ruff.pydocstyle]
342+
[tool.ruff.lint.pydocstyle]
333343
convention = "pep257"
334344

335345
[tool.setuptools.dynamic]
336346
dependencies = {file = [".config/requirements.in"]}
337-
optional-dependencies.dev = {file = [".config/requirements-dev.in"]}
338347
optional-dependencies.docs = {file = [".config/requirements-docs.in"]}
339348
optional-dependencies.test = {file = [".config/requirements-test.in"]}
340349

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Global conftest.py for pytest.
2+
3+
The root package import below happens before the pytest workers are forked, so it
4+
picked up by the initial coverage process for a source match.
5+
6+
Without it, coverage reports the following false positive error:
7+
8+
CoverageWarning: No data was collected. (no-data-collected)
9+
10+
This works in conjunction with the coverage source_pkg set to the package such that
11+
a `coverage run --debug trace` shows the source package and file match.
12+
13+
<...>
14+
Imported source package 'ansible_dev_environment' as '/**/src/<package>/__init__.py'
15+
<...>
16+
Tracing '/**/src/<package>/__init__.py'
17+
"""
18+
19+
import ansible_dev_environment # noqa: F401

tox.ini

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ pass_env =
2525
TERM
2626
USER
2727
set_env =
28+
COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}}
2829
COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml
2930
FORCE_COLOR = 1
3031
PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt
3132
PRE_COMMIT_COLOR = always
3233
TERM = xterm-256color
3334
commands_pre =
34-
sh -c "rm -f .coverage* coverage.xml 2>/dev/null || true"
35+
python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")'
36+
sh -c "rm -f {envdir}/.coverage* 2>/dev/null || true"
3537
commands =
36-
coverage run -m pytest {posargs}
37-
commands_post =
38-
py,py{39,310,311,312}: sh -c "coverage combine .coverage.*"
39-
py,py{39,310,311,312}: coverage xml
40-
py,py{39,310,311,312}: coverage report
41-
git diff --exit-code
38+
coverage run -m pytest {posargs:-n auto}
39+
{py,py310,py311,py312,py313}: sh -c " \
40+
coverage combine -q --data-file={envdir}/.coverage {envdir}/.coverage.* && \
41+
coverage xml --data-file={envdir}/.coverage -o {envdir}/coverage.xml --ignore-errors --fail-under=0 && \
42+
COVERAGE_FILE={envdir}/.coverage coverage lcov --fail-under=0 --ignore-errors -q && \
43+
COVERAGE_FILE={envdir}/.coverage coverage report --fail-under=0 --ignore-errors \
44+
"
4245
allowlist_externals =
4346
git
4447
rm

0 commit comments

Comments
 (0)