summaryrefslogtreecommitdiff
path: root/gnu/packages/aux-files/python/pytest_guix.py
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/packages/aux-files/python/pytest_guix.py')
-rw-r--r--gnu/packages/aux-files/python/pytest_guix.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/gnu/packages/aux-files/python/pytest_guix.py b/gnu/packages/aux-files/python/pytest_guix.py
new file mode 100644
index 00000000000..750b1e99e99
--- /dev/null
+++ b/gnu/packages/aux-files/python/pytest_guix.py
@@ -0,0 +1,68 @@
1# GNU Guix --- Functional package management for GNU
2# Copyright © 2025 Nicolas Graves <ngraves@ngraves.fr>
3#
4# This file is part of GNU Guix.
5#
6# GNU Guix is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or (at
9# your option) any later version.
10#
11# GNU Guix is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19import importlib.util
20
21
22def pytest_addoption(parser):
23 """Add stub options to be ignored by pytest.
24
25 More precisely, inject all options provided in .pytest_guix_options.json,
26 except options whose plugin is indeed installed.
27
28 For example, if the json file records --cov:
29 if the pytest_cov module is installed, its --cov will be used.
30 otherwise, --cov is ignored (read by this parser, but nothing is done
31 with it).
32
33 This allows to remove development packages, which are not required at build
34 time while at the same time avoiding the need to adjust test options in
35 pyproject.toml or other configuration files.
36 """
37 plugin_options = {
38 "cov": [
39 "--cov",
40 "--cov-reset",
41 "--cov-report",
42 "--cov-config",
43 "--no-cov-on-fail",
44 "--no-cov",
45 "--cov-fail-under",
46 "--cov-append",
47 "--cov-branch",
48 "--cov-context",
49 ],
50 "mypy": ["--mypy", "--mypy-config-file", "--mypy-ignore-missing-imports"],
51 "isort": ["--isort"],
52 "flake8": ["--flake8"],
53 "black": ["--black"],
54 "flakes": ["--flakes"],
55 "pep8": ["--pep8"],
56 "html": ["--html", "--self-contained-html", "--css"],
57 }
58
59 group = parser.getgroup(
60 "guix", "Options ignored by the Guix pyproject-build-system"
61 )
62
63 # Only add options for plugins that are not present.
64 for key, options in plugin_options.items():
65 if importlib.util.find_spec(f"pytest_{key}") is None:
66 # Plugin not found, add stub options
67 for option in options:
68 group.addoption(option, action="append", nargs="?")