Skip to content

Commit 89099dd

Browse files
author
Alex Remedios
authored
disable when debugging (#9)
1 parent 82c5a88 commit 89099dd

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

python-cli/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ build-backend = "poetry.core.masonry.api"
3737
addopts = [
3838
"--ignore=tests/resources",
3939
"--strict-markers",
40-
# "--capture=tee-sys",
41-
"--forked"
40+
"--capture=tee-sys",
41+
"--forked",
42+
"-p","no:deeptest"
4243
]
4344

4445
[tool.poetry.plugins."pytest11"]
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
import shutil
2-
from typing import Any
2+
from typing import Any, List, cast
33

44
from _pytest.config import Config
5-
from pytest import ExitCode
5+
from _pytest.config.argparsing import Parser
6+
from pytest import ExitCode, hookimpl
67

78
out_path = ".deeptest/junit.xml"
9+
import sys
810

911

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
1235
config.option.xmlpath = out_path
1336

1437

1538
def pytest_terminal_summary(
1639
terminalreporter: Any, exitstatus: ExitCode, config: Config
1740
):
18-
if not config.option.xmlpath == out_path:
41+
if is_enabled(config) and config.option.xmlpath != out_path:
1942
print(f"Copying {config.option.xmlpath} to {out_path}")
2043
shutil.copy(config.option.xmlpath, out_path)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
22
addopts =
33
--cov=src
4-
--cov-context=test
4+
--cov-context=test

python-cli/tests/test_pytest_plugin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import print_function
22

3+
import os
4+
import sys
35
from distutils.dir_util import copy_tree
46
from pathlib import Path
57

@@ -33,3 +35,14 @@ def test_when_other_xml_then_output_correctly(testdir: Testdir, fake_repo: objec
3335
assert hook_recorder.ret == ExitCode.TESTS_FAILED
3436
assert Path(".deeptest/junit.xml").exists()
3537
assert Path("junit.xml").exists()
38+
39+
40+
def test_when_trace_present_then_disables_cov(testdir: Testdir, fake_repo: object):
41+
print(os.getcwd())
42+
shutil.rmtree(".deeptest", ignore_errors=True)
43+
assert not Path(".deeptest/junit.xml").exists()
44+
sys.settrace(lambda x, y, z: None)
45+
hook_recorder = testdir.inline_run()
46+
47+
assert hook_recorder.ret == ExitCode.TESTS_FAILED
48+
assert not Path(".deeptest/junit.xml").exists()

0 commit comments

Comments
 (0)