| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | import importlib.util
|
| 20 | import json
|
| 21 |
|
| 22 |
|
| 23 | def pytest_addoption(parser):
|
| 24 | |
| 25 |
|
| 26 | More precisely, inject all options provided in .pytest_guix_options.json,
|
| 27 | except options whose plugin is indeed installed.
|
| 28 |
|
| 29 | For example, if the json file records --cov:
|
| 30 | if the pytest_cov module is installed, its --cov will be used.
|
| 31 | otherwise, --cov is ignored (read by this parser, but nothing is done
|
| 32 | with it).
|
| 33 |
|
| 34 | Flags can be given with additional keyword arguments in a json object.
|
| 35 | If the json object is not given, fallback to the default
|
| 36 | {"action": "append", "nargs": "?"}. In practice, these arguments are only
|
| 37 | mandatory for the store_true and store_const actions to avoid eating other
|
| 38 | arguments.
|
| 39 |
|
| 40 | This allows to remove development packages, which are not required at build
|
| 41 | time while at the same time avoiding the need to adjust test options in
|
| 42 | pyproject.toml or other configuration files.
|
| 43 |
|
| 44 | with open(".pytest_guix_options.json", "r") as options_file:
|
| 45 | plugin_options = json.load(options_file)
|
| 46 | group = parser.getgroup(
|
| 47 | "guix", "Options ignored by the Guix pyproject-build-system"
|
| 48 | )
|
| 49 |
|
| 50 | |
| 51 | for key, options in plugin_options.items():
|
| 52 | if importlib.util.find_spec(f"pytest_{key}") is None:
|
| 53 | |
| 54 | for option, kwargs in options.items():
|
| 55 | if kwargs:
|
| 56 | group.addoption(option, **kwargs)
|
| 57 | else:
|
| 58 | group.addoption(option, action="append", nargs="?")
|