Marco Ricci commited on 2026-08-23 12:24:05
Zeige 1 geänderte Dateien mit 7 Einfügungen und 2 Löschungen.
In commit 0bf24eb16ec698d7759657cb810385ec7388f74c, we added the current directory explicitly to pytest's `pythonpath` configuration to avoid failing tests. Further analysis revealed that the culprit was the multiprocessing module with the `spawn` method, which needs to re-import the module it is called from (and other helper code from the `tests.data` and `tests.machinery` submodules), but is not compatible with some ways of modifying Python's module search path before module loading. According to my search results, the common way of dealing with this problem is instead to add the `tests` path to `pythonpath`, instead of the parent directory. Furthermore, it is unnecessary to explicitly add the `src` directory to `pythonpath`, as the virtualenv in which the tests run already has `derivepassphrase` installed. So we can reduce the `pythonpath` to only `tests`, and add an appropriate comment as to why this entry specifically is needed. We also add comments to the entries in `testpaths`, because it may not be immediately obvious that the `src` entry is needed for the doctests.
| ... | ... |
@@ -457,8 +457,13 @@ unnecessary-type-conversion = "ignore" |
| 457 | 457 |
|
| 458 | 458 |
[tool.pytest.ini_options] |
| 459 | 459 |
addopts = '--doctest-modules --dist=loadgroup --import-mode=importlib' |
| 460 |
-pythonpath = ['src', '.'] |
|
| 461 |
-testpaths = ['src', 'tests'] |
|
| 460 |
+pythonpath = [ |
|
| 461 |
+ 'tests', # needed for re-importing test machinery with multiprocessing (spawn) |
|
| 462 |
+] |
|
| 463 |
+testpaths = [ |
|
| 464 |
+ 'src', # doctests in API documentation |
|
| 465 |
+ 'tests', # other tests |
|
| 466 |
+] |
|
| 462 | 467 |
xfail_strict = true |
| 463 | 468 |
|
| 464 | 469 |
[tool.ruff] |
| 465 | 470 |