|
1 | 1 | import shutil |
2 | | -from typing import Any |
| 2 | +from typing import Any, List, cast |
3 | 3 |
|
4 | 4 | from _pytest.config import Config |
5 | | -from pytest import ExitCode |
| 5 | +from _pytest.config.argparsing import Parser |
| 6 | +from pytest import ExitCode, hookimpl |
6 | 7 |
|
7 | 8 | out_path = ".deeptest/junit.xml" |
| 9 | +import sys |
8 | 10 |
|
9 | 11 |
|
10 | | -def pytest_configure(config): |
11 | | - if config.option.xmlpath is None: |
| 12 | +def is_enabled(config: Config) -> bool: |
| 13 | + return not cast(bool, config.option.no_cov) and cast(bool, config.option.cov_source) |
| 14 | + |
| 15 | + |
| 16 | +@hookimpl(hookwrapper=True) |
| 17 | +def pytest_load_initial_conftests( |
| 18 | + early_config: Config, parser: Parser, args: List[str] |
| 19 | +): |
| 20 | + # raise Exception() |
| 21 | + if sys.gettrace(): |
| 22 | + early_config.known_args_namespace.cov_source = None |
| 23 | + # early_config.pluginmanager.set_blocked('pytest_cov') |
| 24 | + early_config.option.no_cov = True |
| 25 | + # args=["--no-cov"] |
| 26 | + |
| 27 | + yield |
| 28 | + |
| 29 | + |
| 30 | +# def pytest_sessionstart(session): |
| 31 | +# pass |
| 32 | +def pytest_configure(config: Config): |
| 33 | + if is_enabled(config) and config.option.xmlpath is None: |
| 34 | + # 1/0 |
12 | 35 | config.option.xmlpath = out_path |
13 | 36 |
|
14 | 37 |
|
15 | 38 | def pytest_terminal_summary( |
16 | 39 | terminalreporter: Any, exitstatus: ExitCode, config: Config |
17 | 40 | ): |
18 | | - if not config.option.xmlpath == out_path: |
| 41 | + if is_enabled(config) and config.option.xmlpath != out_path: |
19 | 42 | print(f"Copying {config.option.xmlpath} to {out_path}") |
20 | 43 | shutil.copy(config.option.xmlpath, out_path) |
0 commit comments