Skip to content

Commit 6798042

Browse files
Fix conflict with other Pytest plugins (#297)
1 parent 43bbdd0 commit 6798042

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release type: patch
2+
3+
Adjust signature of SugarTerminalReporter to avoid conflicts with other pytest plugins

pytest_sugar.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import sys
1717
import time
1818
from configparser import ConfigParser # type: ignore
19-
from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union
19+
from typing import Any, Dict, Generator, List, Optional, Sequence, TextIO, Tuple, Union
2020

2121
import pytest
22+
from _pytest.config import Config
2223
from _pytest.config.argparsing import Parser
2324
from _pytest.main import Session
2425
from _pytest.nodes import Item
@@ -206,7 +207,7 @@ def pytest_configure(config) -> None:
206207
if IS_SUGAR_ENABLED and not getattr(config, "slaveinput", None):
207208
# Get the standard terminal reporter plugin and replace it with our
208209
standard_reporter = config.pluginmanager.getplugin("terminalreporter")
209-
sugar_reporter = SugarTerminalReporter(standard_reporter)
210+
sugar_reporter = SugarTerminalReporter(standard_reporter.config)
210211
config.pluginmanager.unregister(standard_reporter)
211212
config.pluginmanager.register(sugar_reporter, "terminalreporter")
212213

@@ -245,9 +246,9 @@ def pytest_report_teststatus(report: BaseReport) -> Optional[Tuple[str, str, str
245246
return report.outcome, letter, report.outcome.upper()
246247

247248

248-
class SugarTerminalReporter(TerminalReporter): # type: ignore
249-
def __init__(self, reporter) -> None:
250-
TerminalReporter.__init__(self, reporter.config)
249+
class SugarTerminalReporter(TerminalReporter):
250+
def __init__(self, config: Config, file: Union[TextIO, None] = None) -> None:
251+
TerminalReporter.__init__(self, config, file)
251252
self.paths_left = []
252253
self.tests_count = 0
253254
self.tests_taken = 0

test_sugar.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import io
12
import re
23

34
import pytest
45

5-
from pytest_sugar import strip_colors
6+
from pytest_sugar import SugarTerminalReporter, strip_colors
67

78
pytest_plugins = "pytester"
89

@@ -52,6 +53,16 @@ def assert_count(testdir, *args):
5253

5354

5455
class TestTerminalReporter:
56+
def test_sugar_terminal_reporter_init_signature(self, pytestconfig):
57+
terminal_reporter = pytestconfig.pluginmanager.getplugin("terminalreporter")
58+
sugar_reporter = SugarTerminalReporter(terminal_reporter.config)
59+
assert sugar_reporter.config is terminal_reporter.config
60+
61+
file_obj = io.StringIO()
62+
sugar_reporter = SugarTerminalReporter(terminal_reporter.config, file=file_obj)
63+
assert sugar_reporter.config is terminal_reporter.config
64+
assert sugar_reporter._tw._file is file_obj
65+
5566
def test_new_summary(self, testdir):
5667
testdir.makepyfile(
5768
"""

0 commit comments

Comments
 (0)