|
7 | 7 |
|
8 | 8 |
|
9 | 9 | def pytest_addoption(parser: pytest.Parser) -> None: |
10 | | - """Add command line options to pytest. |
| 10 | + """Register pytest command-line options. |
11 | 11 |
|
12 | | - This function is called early by pytest to register custom options. |
13 | | - These options may also be defined in pyinterp/tests/conftest.py |
14 | | - when pytest runs from the build directory. |
| 12 | + This root conftest.py adds options only when they are not already |
| 13 | + defined in pyinterp/tests/conftest.py, preventing duplicate registration. |
15 | 14 | """ |
16 | | - # Only add options if they haven't been added already |
17 | | - try: |
18 | | - parser.addoption('--visualize', action='store_true', default=False) |
19 | | - parser.addoption('--dump', action='store_true', default=False) |
20 | | - parser.addoption('--measure-coverage', |
21 | | - action='store_true', |
22 | | - default=False) |
23 | | - except ValueError: |
24 | | - pass # Already added |
| 15 | + |
| 16 | + def add_option_if_not_exists(option_name: str, |
| 17 | + **kwargs: str | bool) -> None: |
| 18 | + """Add option only if it doesn't already exist.""" |
| 19 | + try: |
| 20 | + parser.addoption(option_name, **kwargs) |
| 21 | + except ValueError: |
| 22 | + pass # Option already registered |
| 23 | + |
| 24 | + add_option_if_not_exists('--visualize', action='store_true', default=False) |
| 25 | + add_option_if_not_exists('--dump', action='store_true', default=False) |
| 26 | + add_option_if_not_exists('--measure-coverage', |
| 27 | + action='store_true', |
| 28 | + default=False) |
0 commit comments